diff --git a/sgip/receiver.go b/sgip/receiver.go index 3e77ce8..0e9e893 100644 --- a/sgip/receiver.go +++ b/sgip/receiver.go @@ -79,7 +79,7 @@ func (r *Receiver) worker(id int) { log.Println("worker ", id, ": Accept ", conn) - session := NewSession(conn, r.handler, r.done) + session := NewSession(conn, r.handler, r.done, r.debug) // block session.Run() } diff --git a/sgip/session.go b/sgip/session.go index e419e41..f71fcd1 100644 --- a/sgip/session.go +++ b/sgip/session.go @@ -20,9 +20,15 @@ type Session struct { isClose uint64 done chan struct{} serverDone chan struct{} + + // debug flag + debug bool } -func NewSession(connection net.Conn, handler Handler, done chan struct{}) *Session { +func NewSession( + connection net.Conn, handler Handler, + done chan struct{}, debug bool, +) *Session { return &Session{ handler: handler, @@ -30,6 +36,7 @@ func NewSession(connection net.Conn, handler Handler, done chan struct{}) *Sessi pipe: make(chan protocol.Operation), done: make(chan struct{}), serverDone: done, + debug: debug, } } @@ -102,6 +109,10 @@ func (s *Session) recvWorker() { return } + if s.debug { + log.Println(op) + } + s.pipe <- op } }