You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

conn_manager.go 641 B

3 dagen geleden
2 dagen geleden
3 dagen geleden
123456789101112131415161718192021222324252627282930313233343536
  1. package connect
  2. import (
  3. "egg-im/pkg/pb"
  4. "sync"
  5. )
  6. var ConnsManager = sync.Map{}
  7. // SetConn 存储
  8. func SetConn(deviceId int64, conn *Conn) {
  9. ConnsManager.Store(deviceId, conn)
  10. }
  11. // GetConn 获取
  12. func GetConn(deviceId int64) *Conn {
  13. value, ok := ConnsManager.Load(deviceId)
  14. if ok {
  15. return value.(*Conn)
  16. }
  17. return nil
  18. }
  19. // DeleteConn 删除
  20. func DeleteConn(deviceId int64) {
  21. ConnsManager.Delete(deviceId)
  22. }
  23. // PushAll 全服推送
  24. func PushAll(message *pb.MessageSend) {
  25. ConnsManager.Range(func(key, value interface{}) bool {
  26. conn := value.(*Conn)
  27. conn.Send(pb.PackageType_PT_MESSAGE, 0, message, nil)
  28. return true
  29. })
  30. }