Socket.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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-25
  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. #include "SocketParameter.hpp"
  14. #include "SocketAddressMapperParameter.hpp"
  15. #include <memory>
  16. #include <ls_std/core/types/Types.hpp>
  17. #include <ls_std/core/interface/IReader.hpp>
  18. namespace ls::std::network
  19. {
  20. class LS_STD_DYNAMIC_GOAL Socket : public ls::std::core::Class, public ls::std::core::interface_type::IReader
  21. {
  22. public:
  23. explicit Socket(ls::std::network::SocketParameter _parameter);
  24. ~Socket() override;
  25. // implementation
  26. [[nodiscard]] ls::std::core::type::byte_field read() override;
  27. // other functionalities
  28. [[nodiscard]] bool accept();
  29. [[nodiscard]] bool bind();
  30. [[nodiscard]] bool close();
  31. [[nodiscard]] bool connect();
  32. [[nodiscard]] bool isInitialized() const;
  33. [[nodiscard]] bool listen();
  34. private:
  35. bool initialized{};
  36. ls::std::network::SocketParameter parameter{};
  37. ls::std::core::type::byte* readBuffer{};
  38. bool readBufferSet{};
  39. #if defined(unix) || defined(__APPLE__)
  40. int unixDescriptor{};
  41. #endif
  42. #if defined(unix) || defined(__APPLE__)
  43. [[nodiscard]] bool _acceptUnix();
  44. [[nodiscard]] bool _bindUnix();
  45. [[nodiscard]] bool _closeUnix();
  46. [[nodiscard]] bool _connectUnix();
  47. #endif
  48. [[nodiscard]] SocketAddressMapperParameter _createSocketAddressMapperParameter() const;
  49. [[nodiscard]] bool _init();
  50. void _initReadBuffer();
  51. #if defined(unix) || defined(__APPLE__)
  52. [[nodiscard]] bool _initUnix();
  53. [[nodiscard]] bool _listenUnix();
  54. #endif
  55. ls::std::core::type::byte_field _read();
  56. #if defined(unix) || defined(__APPLE__)
  57. ls::std::core::type::byte_field _readUnix();
  58. void _setPosixReaderApi();
  59. void _setPosixSocketApi();
  60. #endif
  61. };
  62. }
  63. #endif