isession.go 737 B

12345678910111213141516171819202122232425262728293031323334353637
  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. ServerAddr() string
  21. GetRawConn() IConn
  22. }
  23. type ISessionCallback interface {
  24. OnClosed(ISession, int32)
  25. OnConnected(ISession) (bool, int32)
  26. OnMessage(ISession, IPacket) bool
  27. OnHeartbeat(ISession) bool
  28. }