AService.cs 923 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Sockets;
  5. using System.Threading.Tasks;
  6. namespace Base
  7. {
  8. public enum NetworkProtocol
  9. {
  10. TCP,
  11. UDP
  12. }
  13. public abstract class AService: IDisposable
  14. {
  15. /// <summary>
  16. /// 将函数调用加入IService线程
  17. /// </summary>
  18. /// <param name="action"></param>
  19. public abstract void Add(Action action);
  20. public abstract AChannel GetChannel(long id);
  21. public abstract AChannel GetChannel(string host, int port);
  22. public abstract AChannel GetChannel(string address);
  23. public abstract Task<AChannel> GetChannel();
  24. public abstract void Remove(long channelId);
  25. public abstract void Update();
  26. public Action<long, SocketError> OnError;
  27. protected void OnChannelError(long channelId, SocketError error)
  28. {
  29. this.OnError?.Invoke(channelId, error);
  30. this.Remove(channelId);
  31. }
  32. public abstract void Dispose();
  33. }
  34. }