AsyncServerBase.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace NetCore31BACNetTransfor
  5. {
  6. public class AsyncServerBase
  7. {
  8. private List<AsyncServerBag> sendList = new List<AsyncServerBag>();
  9. private List<AsyncServerBag> receiveList = new List<AsyncServerBag>();
  10. private int packetSize = 1000;
  11. public AsyncServerBase(int packetSize)
  12. {
  13. this.packetSize = packetSize;
  14. }
  15. public void PushSend(AsyncServerBag bag)
  16. {
  17. lock (this.sendList)
  18. {
  19. this.sendList.Add(bag);
  20. while (this.sendList.Count > this.packetSize)
  21. {
  22. this.sendList.RemoveAt(0);
  23. }
  24. }
  25. }
  26. public AsyncServerBag PopSend()
  27. {
  28. AsyncServerBag result = null;
  29. lock (this.sendList)
  30. {
  31. if (this.sendList.Count > 0)
  32. {
  33. result = this.sendList[0];
  34. this.sendList.RemoveAt(0);
  35. }
  36. }
  37. return result;
  38. }
  39. public void PushReceive(AsyncServerBag bag)
  40. {
  41. lock (this.receiveList)
  42. {
  43. this.receiveList.Add(bag);
  44. while (this.receiveList.Count > this.packetSize)
  45. {
  46. this.receiveList.RemoveAt(0);
  47. }
  48. }
  49. }
  50. public AsyncServerBag PopReceive()
  51. {
  52. AsyncServerBag result = null;
  53. lock (this.receiveList)
  54. {
  55. if (this.receiveList.Count > 0)
  56. {
  57. result = this.receiveList[0];
  58. this.receiveList.RemoveAt(0);
  59. }
  60. }
  61. return result;
  62. }
  63. }
  64. }