AService.cs 791 B

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