Socket.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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-11
  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(ls::std::network::SocketParameter _parameter);
  25. ~Socket() override = default;
  26. [[nodiscard]] bool accept();
  27. [[nodiscard]] bool bind();
  28. [[nodiscard]] bool close();
  29. [[nodiscard]] bool connect();
  30. [[nodiscard]] bool isInitialized() const;
  31. [[nodiscard]] bool listen();
  32. private:
  33. bool initialized{};
  34. ls::std::network::SocketParameter parameter{};
  35. #if defined(unix) || defined(__APPLE__)
  36. int unixDescriptor{};
  37. #endif
  38. #if defined(unix) || defined(__APPLE__)
  39. [[nodiscard]] bool _acceptUnix();
  40. [[nodiscard]] bool _bindUnix();
  41. [[nodiscard]] bool _closeUnix();
  42. [[nodiscard]] bool _connectUnix();
  43. #endif
  44. [[nodiscard]] SocketAddressMapperParameter _createSocketAddressMapperParameter() const;
  45. [[nodiscard]] bool _init();
  46. #if defined(unix) || defined(__APPLE__)
  47. [[nodiscard]] bool _initUnix();
  48. [[nodiscard]] bool _listenUnix();
  49. void _setUnixSocketApi();
  50. #endif
  51. };
  52. }
  53. #endif