libnmdc/ConnectionState.go

41 lines
637 B
Go
Raw Normal View History

2016-05-04 07:03:36 +00:00
package libnmdc
import (
"net"
)
type ConnectionState int
const (
CONNECTIONSTATE_DISCONNECTED = 1
CONNECTIONSTATE_CONNECTING = 2 // Handshake in progress
CONNECTIONSTATE_CONNECTED = 3
)
func (cs ConnectionState) String() string {
2016-05-04 07:03:36 +00:00
switch cs {
case CONNECTIONSTATE_DISCONNECTED:
return "Disconnected"
case CONNECTIONSTATE_CONNECTING:
return "Connecting"
case CONNECTIONSTATE_CONNECTED:
return "Connected"
default:
return "?"
}
}
2016-11-29 06:43:32 +00:00
func checkIsNetTimeout(err error) bool {
2016-05-04 07:03:36 +00:00
if err == nil {
return false
}
switch err.(type) {
case net.Error:
return err.(net.Error).Timeout()
default:
return false
}
}