Commit 6a7f8a34 authored by AlexStocks's avatar AlexStocks

Imp: add remark for OnMessage to let user handle the OnMessage asynchronously

parent a5d4d7b1
......@@ -56,9 +56,15 @@ type EventListener interface {
// invoked periodically, its period can be set by (Session)SetCronPeriod
OnCron(Session)
// invoked when receive packge. Pls attention that do not handle long time logic processing in this func.
// You'd better set the package's maximum length. If the message's length is greater than it, u should
// should return err in Reader{Read} and getty will close this connection soon.
// invoked when getty received a package. Pls attention that do not handle long time
// logic processing in this func. You'd better set the package's maximum length.
// If the message's length is greater than it, u should should return err in
// Reader{Read} and getty will close this connection soon.
//
// If ur logic processing in this func will take a long time, u should start a goroutine
// pool(like working thread pool in cpp) to handle the processing asynchronously. Or u
// can do the logic processing in other asynchronous way.
// !!!In short, ur OnMessage callback func should return asap.
//
// If this is a udp event listener, the second parameter type is UDPContext.
OnMessage(Session, interface{})
......
......@@ -489,7 +489,8 @@ LOOP:
if flag {
log.Debug("%#v <-s.rQ", inPkg)
pkg := inPkg
go s.listener.OnMessage(s, pkg)
// go s.listener.OnMessage(s, pkg)
s.listener.OnMessage(s, pkg)
s.incReadPkgNum()
} else {
log.Info("[session.handleLoop] drop readin package{%#v}", inPkg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment