diff --git a/src/libnmdc/libnmdc.go b/src/libnmdc/libnmdc.go index e9b22a7..36b194c 100644 --- a/src/libnmdc/libnmdc.go +++ b/src/libnmdc/libnmdc.go @@ -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