AService.cs 879 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 Task<AChannel> AcceptChannel();
  22. public abstract AChannel ConnectChannel(string host, int port);
  23. public abstract void Remove(long channelId);
  24. public abstract void Update();
  25. public Action<AChannel, SocketError> OnError;
  26. protected void OnChannelError(AChannel channel, SocketError error)
  27. {
  28. this.OnError?.Invoke(channel, error);
  29. this.Remove(channel.Id);
  30. }
  31. public abstract void Dispose();
  32. }
  33. }