isession.go 716 B

123456789101112131415161718192021222324252627282930313233343536
  1. package nnet
  2. import "time"
  3. var (
  4. DEF_SESSION_ID uint64 = 0
  5. RUBBISH_SESSION_ID uint64 = 1
  6. SESSION_ID_START uint64 = 100
  7. )
  8. type ISession interface {
  9. Do() // session
  10. SetFrozen(int32)
  11. Close(int32) //
  12. IsClosed() bool
  13. Write(IPacket, time.Duration) error
  14. AWrite(IPacket, time.Duration) error // async write
  15. GetData() interface{} // user data
  16. SetData(interface{})
  17. UpdateId(uint64) // update session id, this will add session pointer into Hub, indexed by its id
  18. Id() uint64 // get session id
  19. SetId(uint64)
  20. GetRawConn() IConn
  21. }
  22. type ISessionCallback interface {
  23. OnClosed(ISession, int32)
  24. OnConnected(ISession) (bool, int32)
  25. OnMessage(ISession, IPacket) bool
  26. OnHeartbeat(ISession) bool
  27. }