From: Mikko Rasa Date: Sun, 11 Dec 2022 09:43:25 +0000 (+0200) Subject: Move the address family enum into sockaddr.h X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=593c8202bf8c6ecc563aaacf0811aef953b45f09;p=libs%2Fnet.git Move the address family enum into sockaddr.h --- diff --git a/source/net/constants.cpp b/source/net/constants.cpp deleted file mode 100644 index 4de22b4..0000000 --- a/source/net/constants.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "platform_api.h" -#include "constants.h" -#include - -using namespace std; - -namespace Msp { -namespace Net { - -int family_to_sys(Family f) -{ - switch(f) - { - case UNSPEC: return AF_UNSPEC; - case INET: return AF_INET; - case INET6: return AF_INET6; - case UNIX: return AF_UNIX; - default: throw invalid_argument("family_to_sys"); - } -} - -Family family_from_sys(int f) -{ - switch(f) - { - case AF_UNSPEC: return UNSPEC; - case AF_INET: return INET; - case AF_INET6: return INET6; - case AF_UNIX: return UNIX; - default: throw invalid_argument("family_from_sys"); - } -} - -} // namespace Net -} // namespace Msp diff --git a/source/net/constants.h b/source/net/constants.h index 0d94661..2e6d544 100644 --- a/source/net/constants.h +++ b/source/net/constants.h @@ -1,21 +1,8 @@ #ifndef MSP_NET_CONSTANTS_H_ #define MSP_NET_CONSTANTS_H_ -namespace Msp { -namespace Net { +#warning "This header is deprected and should not be used" -enum Family -{ - UNSPEC, - INET, - INET6, - UNIX -}; - -int family_to_sys(Family); -Family family_from_sys(int); - -} // namespace Net -} // namespace Msp +#include "sockaddr.h" #endif diff --git a/source/net/resolve.h b/source/net/resolve.h index ae0411b..212a7f0 100644 --- a/source/net/resolve.h +++ b/source/net/resolve.h @@ -9,13 +9,11 @@ #include #include #include -#include "constants.h" +#include "sockaddr.h" namespace Msp { namespace Net { -class SockAddr; - /** Resolves host and service names into a socket address. If host is empty, the loopback address will be used. If host is "*", the wildcard address will be used. If service is empty, a socket address with a null service will be diff --git a/source/net/sockaddr.cpp b/source/net/sockaddr.cpp index 6ac9189..a3d3eed 100644 --- a/source/net/sockaddr.cpp +++ b/source/net/sockaddr.cpp @@ -31,5 +31,30 @@ SockAddr::SysAddr::SysAddr() addr.ss_family = AF_UNSPEC; } + +int family_to_sys(Family f) +{ + switch(f) + { + case UNSPEC: return AF_UNSPEC; + case INET: return AF_INET; + case INET6: return AF_INET6; + case UNIX: return AF_UNIX; + default: throw invalid_argument("family_to_sys"); + } +} + +Family family_from_sys(int f) +{ + switch(f) + { + case AF_UNSPEC: return UNSPEC; + case AF_INET: return INET; + case AF_INET6: return INET6; + case AF_UNIX: return UNIX; + default: throw invalid_argument("family_from_sys"); + } +} + } // namespace Net } // namespace Msp diff --git a/source/net/sockaddr.h b/source/net/sockaddr.h index 9db8b18..f2f9695 100644 --- a/source/net/sockaddr.h +++ b/source/net/sockaddr.h @@ -2,11 +2,19 @@ #define MSP_NET_SOCKADDR_H_ #include -#include "constants.h" namespace Msp { namespace Net { +enum Family +{ + UNSPEC, + INET, + INET6, + UNIX +}; + + class SockAddr { public: diff --git a/source/net/sockaddr_private.h b/source/net/sockaddr_private.h index 5fca410..2a3d14b 100644 --- a/source/net/sockaddr_private.h +++ b/source/net/sockaddr_private.h @@ -19,6 +19,10 @@ struct SockAddr::SysAddr SysAddr(); }; + +int family_to_sys(Family); +Family family_from_sys(int); + } // namespace Net } // namespace Msp diff --git a/source/net/socket.h b/source/net/socket.h index 7a47793..3e3c2ae 100644 --- a/source/net/socket.h +++ b/source/net/socket.h @@ -5,7 +5,6 @@ #include #include #include -#include "constants.h" #include "sockaddr.h" namespace Msp {