Socket.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 = default;
  27. bool create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  28. private:
  29. #if defined(unix) || defined(__APPLE__)
  30. int descriptor {};
  31. #endif
  32. #ifdef _WIN32
  33. SOCKET descriptor {};
  34. #endif
  35. static int _convertAddressFamily(ls_std::AddressFamily _addressFamily);
  36. static int _convertNetworkProtocol(ls_std::NetworkProtocol _networkProtocol);
  37. static int _convertSocketType(ls_std::SocketType _socketType);
  38. #if defined(unix) || defined(__APPLE__)
  39. static int _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  40. #endif
  41. #ifdef _WIN32
  42. static SOCKET _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  43. #endif
  44. };
  45. }
  46. #endif