diff --git a/server.go b/server.go index d7475bd..ba99f00 100644 --- a/server.go +++ b/server.go @@ -98,13 +98,19 @@ func (s *Server) RunWorker() { buf := make([]byte, CLIENT_READ_BUFFSIZE) + s.clientConn.SetReadDeadline(time.Now().Add(CLIENT_KEEPALIVE_EVERY * time.Second)) ln, err := s.clientConn.Read(buf) + if err != nil { if err == io.EOF { break // abandon thread } // If this was a /timeout/, send a KA and continue. + if libnmdc.CheckIsNetTimeout(err) { + s.writeClient("PING :" + s.name) + continue + } // But otherwise, it was a real error (e.g. unexpected disconnect) s.verboseln(err.Error()) diff --git a/typedefs.go b/typedefs.go index 6e78807..752bc32 100644 --- a/typedefs.go +++ b/typedefs.go @@ -24,9 +24,9 @@ const ( BLESSED_CHANNEL = "#chat" // must be lowercase BLESSED_CHANNEL_MODE = "n" // means that you have to be in the channel to chat, but that's it - NICKS_PER_PROTOMSG = 128 //The capacity sets the max number of nicks to send per message - CLIENT_READ_BUFFSIZE = 512 - CLIENT_READ_TIMEOUT_SEC = 3 + NICKS_PER_PROTOMSG = 128 // Max number of nicks to send per message + CLIENT_READ_BUFFSIZE = 512 + CLIENT_KEEPALIVE_EVERY = 60 // should be longer than the client's one, hexchat is 30s ) type replyCode int