Socket.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 close() const;
  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. static int _convertAddressFamily(ls_std::AddressFamily _addressFamily);
  37. static int _convertNetworkProtocol(ls_std::NetworkProtocol _networkProtocol);
  38. static int _convertSocketType(ls_std::SocketType _socketType);
  39. #if defined(unix) || defined(__APPLE__)
  40. static int _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  41. #endif
  42. #ifdef _WIN32
  43. static SOCKET _create(ls_std::AddressFamily _addressFamily, ls_std::SocketType _socketType, ls_std::NetworkProtocol _networkProtocol);
  44. #endif
  45. };
  46. }
  47. #endif