libnmdc: patch panic on read() returning an error (interface type) that can't be cast to net.error

This commit is contained in:
mappu 2016-04-16 18:27:14 +12:00
parent ed64887ddc
commit 649b3dfcab
1 changed files with 15 additions and 1 deletions

View File

@ -334,6 +334,20 @@ func (this *HubConnection) processProtocolMessage(message string) {
}
}
func CheckIsNetTimeout(err error) bool {
if err == nil {
return false
}
switch err.(type) {
case net.Error:
return err.(net.Error).Timeout()
default:
return false
}
}
func (this *HubConnection) worker() {
var fullBuffer string
var err error = nil
@ -372,7 +386,7 @@ func (this *HubConnection) worker() {
this.conn.SetReadDeadline(time.Now().Add(SEND_KEEPALIVE_EVERY))
nbytes, err = this.conn.Read(readBuff)
if err != nil && err.(net.Error).Timeout() {
if CheckIsNetTimeout(err) {
// No data before read deadline
err = nil