USocketManager.cs 720 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Base
  4. {
  5. internal class USocketManager
  6. {
  7. private readonly Dictionary<IntPtr, USocket> sockets = new Dictionary<IntPtr, USocket>();
  8. public void Add(IntPtr peerPtr, USocket uSocket)
  9. {
  10. this.sockets.Add(peerPtr, uSocket);
  11. }
  12. public void Remove(IntPtr peerPtr)
  13. {
  14. this.sockets.Remove(peerPtr);
  15. }
  16. public bool ContainsKey(IntPtr peerPtr)
  17. {
  18. if (this.sockets.ContainsKey(peerPtr))
  19. {
  20. return true;
  21. }
  22. return false;
  23. }
  24. public USocket this[IntPtr peerPtr]
  25. {
  26. get
  27. {
  28. if (!this.sockets.ContainsKey(peerPtr))
  29. {
  30. throw new KeyNotFoundException("No Peer Key");
  31. }
  32. return this.sockets[peerPtr];
  33. }
  34. }
  35. }
  36. }