PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ClassMaster2014/barahon/Transcend_0.3_UnixSource/minorGems/network/SocketManager.h

https://gitlab.com/garheade/linux_camp
C Header | 90 lines | 21 code | 36 blank | 33 comment | 0 complexity | 6d6ac6922dd2d97cdd04625bd8bfb34b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * Modification History
  3. *
  4. * 2004-December-13 Jason Rohrer
  5. * Created.
  6. */
  7. #ifndef SOCKET_MANAGER_INCLUDED
  8. #define SOCKET_MANAGER_INCLUDED
  9. #include "minorGems/network/Socket.h"
  10. #include "minorGems/system/MutexLock.h"
  11. #include "minorGems/util/SimpleVector.h"
  12. /**
  13. * Ensures proper destruction of static data items at program termination.
  14. */
  15. class SocketManagerDataWrapper {
  16. public:
  17. SocketManagerDataWrapper();
  18. ~SocketManagerDataWrapper();
  19. MutexLock *mLock;
  20. SimpleVector<Socket *> *mSocketVector;
  21. };
  22. /**
  23. * A class that ensures thread-safe socket shutdown and destruction.
  24. *
  25. * Useful if a thread needs to break a socket that another thread is using.
  26. */
  27. class SocketManager {
  28. public:
  29. /**
  30. * Adds a socket to this manager.
  31. *
  32. * @param inSocket the socket to add.
  33. * Will be destroyed by this manager.
  34. */
  35. static void addSocket( Socket *inSocket );
  36. /**
  37. * Breaks the connection (both directions) associated with a socket.
  38. *
  39. * This call is safe even if inSocket has already been destroyed.
  40. *
  41. * @param inSocket the socket to break.
  42. */
  43. static void breakConnection( Socket *inSocket );
  44. /**
  45. * Destroys a socket and removes it from this manager.
  46. *
  47. * @param inSocket the socket to destroy.
  48. */
  49. static void destroySocket( Socket *inSocket );
  50. private:
  51. // allocated statically to ensure destruction on program termination
  52. static SocketManagerDataWrapper mDataWrapper;
  53. };
  54. #endif