isession.go 642 B

1234567891011121314151617181920212223242526272829303132333435
  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. Close(int32) // 停止所有工作
  11. IsClosed() bool
  12. Write(IPacket, time.Duration) error
  13. AWrite(IPacket, time.Duration) error // 异步发送
  14. GetData() interface{} // 辅助数据
  15. SetData(interface{})
  16. UpdateId(uint64) //更新ID
  17. Id() uint64
  18. SetId(uint64)
  19. GetRawConn() IConn
  20. }
  21. type ISessionCallback interface {
  22. OnClosed(ISession, int32)
  23. OnConnected(ISession) (bool, int32)
  24. OnMessage(ISession, IPacket) bool
  25. OnHeartbeat(ISession) bool
  26. }