ProtocolMapper.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-11-17
  6. * Changed: 2022-12-12
  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_UDP:
  29. {
  30. protocol.unixProtocol = SOCK_DGRAM;
  31. } break;
  32. case ls::std::network::ProtocolType::PROTOCOL_TYPE_TCP:
  33. {
  34. protocol.unixProtocol = SOCK_STREAM;
  35. } break;
  36. case ls::std::network::ProtocolType::PROTOCOL_TYPE_NOT_INITIALIZED:
  37. {
  38. throw ls::std::core::IllegalArgumentException{};
  39. }
  40. }
  41. return protocol;
  42. }
  43. #endif