ProtocolMapper.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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-28
  7. *
  8. * */
  9. #include <ls_std/os/specification.hpp>
  10. #include <ls_std/network/core/ProtocolMapper.hpp>
  11. #if LS_STD_UNIX_PLATFORM
  12. #include <sys/socket.h>
  13. #endif
  14. #include <ls_std/core/exception/IllegalArgumentException.hpp>
  15. ls::std::network::ProtocolMapper::ProtocolMapper() : ls::std::core::Class("ProtocolMapper")
  16. {}
  17. ls::std::network::Protocol ls::std::network::ProtocolMapper::from(const ls::std::network::ProtocolType &_protocolType)
  18. {
  19. #if LS_STD_UNIX_PLATFORM
  20. return ls::std::network::ProtocolMapper::_toUnixProtocol(_protocolType);
  21. #endif
  22. }
  23. #if LS_STD_UNIX_PLATFORM
  24. ls::std::network::Protocol ls::std::network::ProtocolMapper::_toUnixProtocol(const ls::std::network::ProtocolType &_protocolType)
  25. {
  26. ls::std::network::Protocol protocol{};
  27. switch (_protocolType)
  28. {
  29. case ls::std::network::ProtocolType::LS_STD_PROTOCOL_TYPE_UDP:
  30. {
  31. protocol.unixProtocol = SOCK_DGRAM;
  32. } break;
  33. case ls::std::network::ProtocolType::LS_STD_PROTOCOL_TYPE_TCP:
  34. {
  35. protocol.unixProtocol = SOCK_STREAM;
  36. } break;
  37. case ls::std::network::ProtocolType::LS_STD_PROTOCOL_TYPE_NOT_INITIALIZED:
  38. {
  39. throw ls::std::core::IllegalArgumentException{};
  40. }
  41. }
  42. return protocol;
  43. }
  44. #endif