Socket.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-11-16
  6. * Changed: 2022-12-10
  7. *
  8. * */
  9. #ifndef LS_STD_SOCKET_HPP
  10. #define LS_STD_SOCKET_HPP
  11. #include <ls_std/os/dynamic_goal.hpp>
  12. #include <ls_std/core/Class.hpp>
  13. #if defined(unix) || defined(__APPLE__)
  14. #include "PosixSocket.hpp"
  15. #endif
  16. #include "SocketParameter.hpp"
  17. #include "SocketAddressMapperParameter.hpp"
  18. #include <memory>
  19. namespace ls::std::network
  20. {
  21. class LS_STD_DYNAMIC_GOAL Socket : public ls::std::core::Class
  22. {
  23. public:
  24. explicit Socket(const ls::std::network::SocketParameter& _parameter);
  25. ~Socket() override = default;
  26. [[nodiscard]] bool bind();
  27. [[nodiscard]] bool connect();
  28. [[nodiscard]] bool isInitialized() const;
  29. private:
  30. bool initialized{};
  31. ls::std::network::SocketParameter parameter{};
  32. #if defined(unix) || defined(__APPLE__)
  33. ::std::shared_ptr<ls::std::core::interface_type::IPosixSocket> posixSocket{};
  34. int unixDescriptor{};
  35. #endif
  36. #if defined(unix) || defined(__APPLE__)
  37. [[nodiscard]] bool _bindUnix();
  38. [[nodiscard]] bool _connectUnix();
  39. #endif
  40. [[nodiscard]] SocketAddressMapperParameter _createSocketAddressMapperParameter() const;
  41. [[nodiscard]] bool _init(const ls::std::network::SocketParameter& _parameter);
  42. #if defined(unix) || defined(__APPLE__)
  43. [[nodiscard]] bool _initUnix(const ls::std::network::SocketParameter& _parameter);
  44. void _selectUnixSocketApi(const ls::std::network::SocketParameter& _parameter);
  45. #endif
  46. };
  47. }
  48. #endif