Skip to content

Commit

Permalink
changed debug output strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfelian committed May 4, 2018
1 parent 7582d30 commit 3c114d5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
12 changes: 6 additions & 6 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}()

Expand Down
15 changes: 8 additions & 7 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,36 @@ 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{}{})
return
}

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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 14 additions & 13 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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")
}
}

Expand Down

0 comments on commit 3c114d5

Please sign in to comment.