From 3c114d5560a56e2f0a600492946bb028055e1af1 Mon Sep 17 00:00:00 2001 From: Artemij Shepelev Date: Fri, 4 May 2018 16:56:51 +0300 Subject: [PATCH] changed debug output strings --- channel.go | 12 ++++++------ event.go | 15 ++++++++------- handler.go | 2 +- server.go | 27 ++++++++++++++------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/channel.go b/channel.go index b8d3856..207e12b 100644 --- a/channel.go +++ b/channel.go @@ -137,16 +137,16 @@ func (c *Channel) inLoop(e *event) error { switch decodedMessage.Type { case protocol.MessageTypeOpen: - logging.Log().Debugf("inLoop(), protocol.MessageTypeOpen: %+v", decodedMessage) + logging.Log().Debugf("inLoop(), protocol.MessageTypeOpen, decodedMessage: %+v", decodedMessage) if err := json.Unmarshal([]byte(decodedMessage.Source[1:]), &c.connHeader); err != nil { c.close(e) } e.callLoopEvent(c, OnConnection) case protocol.MessageTypePing: - logging.Log().Debugf("inLoop(), protocol.MessageTypePing: %+v", decodedMessage) + logging.Log().Debugf("inLoop(), protocol.MessageTypePing, decodedMessage: %+v", decodedMessage) if decodedMessage.Source == protocol.MessagePingProbe { - logging.Log().Debugf("inLoop(), got %s", decodedMessage.Source) + logging.Log().Debugf("inLoop(), decodedMessage.Source: %s", decodedMessage.Source) c.outC <- protocol.MessagePongProbe c.upgradedC <- transport.UpgradedMessage } else { @@ -168,7 +168,7 @@ func (c *Channel) inLoop(e *event) error { func (c *Channel) outLoop(e *event) error { for { outBufferLen := len(c.outC) - logging.Log().Debug("outLoop(), outBufferLen: ", outBufferLen) + logging.Log().Debug("outLoop(), outBufferLen:", outBufferLen) switch { case outBufferLen >= queueBufferSize-1: logging.Log().Debug("outLoop(), outBufferLen >= queueBufferSize-1") @@ -190,7 +190,7 @@ func (c *Channel) outLoop(e *event) error { } if err := c.conn.WriteMessage(msg); err != nil { - logging.Log().Debug("outLoop(), failed to c.conn.WriteMessage(), err: ", err) + logging.Log().Debug("outLoop(), failed to c.conn.WriteMessage() with err:", err) return c.close(e) } } @@ -215,7 +215,7 @@ func (c *Channel) send(m *protocol.Message, payload interface{}) error { // preventing encoding/json "index out of range" panic defer func() { if r := recover(); r != nil { - logging.Log().Warn("socket.io send panic: ", r) + logging.Log().Warn("socket.io send panic:", r) } }() diff --git a/event.go b/event.go index 78ed649..acfdabc 100644 --- a/event.go +++ b/event.go @@ -74,17 +74,17 @@ func (e *event) callLoopEvent(c *Channel, event string) { // processIncomingEvent checks incoming message func (e *event) processIncomingEvent(c *Channel, msg *protocol.Message) { - logging.Log().Debug("processIncomingEvent(): ", msg) + logging.Log().Debug("processIncomingEvent() fired with:", msg) switch msg.Type { case protocol.MessageTypeEmit: - logging.Log().Debug("processIncomingEvent() is finding handler: ", msg.Event) + logging.Log().Debug("processIncomingEvent() is finding handler for msg.Event:", msg.Event) f, ok := e.findEvent(msg.Event) if !ok { logging.Log().Debug("processIncomingEvent(): handler not found") return } - logging.Log().Debug("processIncomingEvent() found method: ", f) + logging.Log().Debug("processIncomingEvent() found handler:", f) if !f.hasArgs { f.call(c, &struct{}{}) @@ -92,17 +92,18 @@ func (e *event) processIncomingEvent(c *Channel, msg *protocol.Message) { } data := f.arguments() - logging.Log().Debug("processIncomingEvent(): f.arguments() returned ", data) + logging.Log().Debug("processIncomingEvent(), f.arguments() returned:", data) if err := json.Unmarshal([]byte(msg.Args), &data); err != nil { - logging.Log().Infof("Error processing message. msg.Args: %s, data: %v, err: %v", msg.Args, data, err) + logging.Log().Infof("processIncomingEvent() failed to json.Unmaeshal(). msg.Args: %s, data: %v, err: %v", + msg.Args, data, err) return } f.call(c, data) case protocol.MessageTypeAckRequest: - logging.Log().Debug("processIncomingEvent(): ack request") + logging.Log().Debug("processIncomingEvent() ack request") f, ok := e.findEvent(msg.Event) if !ok || !f.out { return @@ -128,7 +129,7 @@ func (e *event) processIncomingEvent(c *Channel, msg *protocol.Message) { c.send(ackResponse, result[0].Interface()) case protocol.MessageTypeAckResponse: - logging.Log().Debug("processIncomingEvent(): ack response") + logging.Log().Debug("processIncomingEvent() ack response") ackC, err := c.ack.obtain(msg.AckId) if err == nil { ackC <- msg.Args diff --git a/handler.go b/handler.go index f40ec63..4a197a6 100644 --- a/handler.go +++ b/handler.go @@ -19,7 +19,7 @@ var ( ErrorHandlerWrongResult = errors.New("f should return no more than one value") ) -// newHandler parses function f (event handler) using reflection, and stores its representation +// newHandler parses function f (event handler) using reflection, and stores it's representation func newHandler(f interface{}) (*handler, error) { fVal := reflect.ValueOf(f) if fVal.Kind() != reflect.Func { diff --git a/server.go b/server.go index 95f5c67..abb6e23 100644 --- a/server.go +++ b/server.go @@ -139,8 +139,8 @@ func onDisconnection(c *Channel) { defer func() { c.server.sidsMu.Lock() - defer c.server.sidsMu.Unlock() delete(c.server.sids, c.Id()) + c.server.sidsMu.Unlock() }() _, ok := c.server.rooms[c] @@ -159,6 +159,7 @@ func onDisconnection(c *Channel) { delete(c.server.rooms, c) } +// sendOpenSequence to the given channel c func (s *Server) sendOpenSequence(c *Channel) { jsonHdr, err := json.Marshal(&c.connHeader) if err != nil { @@ -168,7 +169,7 @@ func (s *Server) sendOpenSequence(c *Channel) { c.outC <- protocol.MustEncode(&protocol.Message{Type: protocol.MessageTypeEmpty}) } -// setupEventLoop for the given connection +// setupEventLoop for the given connection conn on the given address with HTTP header func (s *Server) setupEventLoop(conn transport.Connection, address string, header http.Header) { interval, timeout := conn.PingParams() connHeader := connectionHeader{ @@ -203,15 +204,15 @@ func (s *Server) setupEventLoop(conn transport.Connection, address string, heade // upgradeEventLoop at transport upgrade func (s *Server) upgradeEventLoop(conn transport.Connection, remoteAddr string, header http.Header, sid string) { - logging.Log().Debug("upgradeEventLoop(): entered") + logging.Log().Debug("upgradeEventLoop() fired") - cPolling, err := s.GetChannel(sid) + pollingChannel, err := s.GetChannel(sid) if err != nil { - logging.Log().Warnf("upgradeEventLoop() can't find channel for session %s", sid) + logging.Log().Warn("upgradeEventLoop() can't find channel for session:", sid) return } - logging.Log().Debug("upgradeEventLoop() obtained channel") + logging.Log().Debug("upgradeEventLoop() obtained a polling channel") interval, timeout := conn.PingParams() connHeader := connectionHeader{ Sid: sid, @@ -222,17 +223,17 @@ func (s *Server) upgradeEventLoop(conn transport.Connection, remoteAddr string, c := &Channel{conn: conn, address: remoteAddr, header: header, server: s, connHeader: connHeader} c.init() - logging.Log().Debug("upgradeEventLoop init channel") + logging.Log().Debug("upgradeEventLoop() initialized a new channel") go c.inLoop(s.event) go c.outLoop(s.event) - logging.Log().Debug("upgradeEventLoop go loops") + logging.Log().Debug("upgradeEventLoop() fired c.inLoop() and c.outLoop() in separate go-routines") onConnection(c) // synchronize stubbing polling channel with receiving "2probe" message <-c.upgradedC - cPolling.stub() + pollingChannel.stub() } // ServeHTTP makes Server to implement http.Handler @@ -253,19 +254,19 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } s.setupEventLoop(conn, r.RemoteAddr, r.Header) - logging.Log().Debug("PollingConnection created") + logging.Log().Debug("ServeHTTP() created a PollingConnection") conn.(*transport.PollingConnection).PollingWriter(w, r) case "websocket": if session != "" { - logging.Log().Debug("upgrade HandleConnection") + logging.Log().Debug("ServeHTTP() is firing s.websocket.HandleConnection() for upgrade") conn, err := s.websocket.HandleConnection(w, r) if err != nil { logging.Log().Debug("upgrade error ", err) return } s.upgradeEventLoop(conn, r.RemoteAddr, r.Header, session) - logging.Log().Debug("WebsocketConnection upgraded") + logging.Log().Debug("ServeHTTP() upgraded to a WebsocketConnection") return } @@ -275,7 +276,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } s.setupEventLoop(conn, r.RemoteAddr, r.Header) - logging.Log().Debug("WebsocketConnection created") + logging.Log().Debug("ServeHTTP() created a WebsocketConnection") } }