Socket.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-06
  6. * Changed: 2020-12-06
  7. *
  8. * */
  9. #ifndef LS_STD_SOCKET_HPP
  10. #define LS_STD_SOCKET_HPP
  11. #include <ls_std/base/Class.hpp>
  12. #include "AddressFamily.hpp"
  13. #include "SocketType.hpp"
  14. #include "NetworkProtocol.hpp"
  15. #if defined(unix) || defined(__APPLE__)
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #endif
  19. #ifdef _WIN32
  20. #include <winsock2.h>
  21. #endif
  22. namespace ls_std {
  23. class Socket : public ls_std::Class {
  24. public:
  25. Socket();
  26. ~Socket() override;
  27. bool close();
  28. bool create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  29. private:
  30. #if defined(unix) || defined(__APPLE__)
  31. int descriptor {};
  32. #endif
  33. #ifdef _WIN32
  34. SOCKET descriptor {};
  35. #endif
  36. bool _close();
  37. #ifdef _WIN32
  38. bool _closeOnWindows() const;
  39. #endif
  40. static int _convertAddressFamily(ls_std::AddressFamily _addressFamily);
  41. static int _convertNetworkProtocol(ls_std::NetworkProtocol _networkProtocol);
  42. static int _convertSocketType(ls_std::SocketType _socketType);
  43. #if defined(unix) || defined(__APPLE__)
  44. static int _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  45. #endif
  46. #ifdef _WIN32
  47. static SOCKET _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  48. #endif
  49. };
  50. }
  51. #endif