ProtocolMapper.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-11-17
  6. * Changed: 2022-11-17
  7. *
  8. * */
  9. #include <ls_std/network/core/ProtocolMapper.hpp>
  10. #if defined(unix) || defined(__APPLE__)
  11. #include <sys/socket.h>
  12. #endif
  13. #include <ls_std/core/exception/IllegalArgumentException.hpp>
  14. ls::std::network::ProtocolMapper::ProtocolMapper() : ls::std::core::Class("ProtocolMapper")
  15. {}
  16. ls::std::network::Protocol ls::std::network::ProtocolMapper::from(const ls::std::network::ProtocolType &_protocolType)
  17. {
  18. #if defined(unix) || defined(__APPLE__)
  19. return ls::std::network::ProtocolMapper::_toUnixProtocol(_protocolType);
  20. #endif
  21. }
  22. #if defined(unix) || defined(__APPLE__)
  23. ls::std::network::Protocol ls::std::network::ProtocolMapper::_toUnixProtocol(const ls::std::network::ProtocolType &_protocolType)
  24. {
  25. ls::std::network::Protocol protocol{};
  26. switch (_protocolType)
  27. {
  28. case ls::std::network::ProtocolType::PROTOCOL_TYPE_TCP:
  29. {
  30. protocol.unixProtocol = SOCK_STREAM;
  31. } break;
  32. case ls::std::network::ProtocolType::PROTOCOL_TYPE_NOT_INITIALIZED:
  33. {
  34. throw ls::std::core::IllegalArgumentException{};
  35. }
  36. }
  37. return protocol;
  38. }
  39. #endif