From: Mikko Rasa Date: Sat, 6 Aug 2011 12:03:04 +0000 (+0300) Subject: Hide AF_* constants from the public header X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=bdd968802348fae7a7a407616cb3744e4877601a;p=libs%2Fnet.git Hide AF_* constants from the public header --- diff --git a/source/constants.cpp b/source/constants.cpp new file mode 100644 index 0000000..e57897d --- /dev/null +++ b/source/constants.cpp @@ -0,0 +1,39 @@ +#include +#ifdef WIN32 +#include +#else +#include +#endif +#include "constants.h" + +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/constants.h b/source/constants.h index 4feefcc..0d94661 100644 --- a/source/constants.h +++ b/source/constants.h @@ -1,23 +1,20 @@ #ifndef MSP_NET_CONSTANTS_H_ #define MSP_NET_CONSTANTS_H_ -#ifdef WIN32 -#include -#else -#include -#endif - namespace Msp { namespace Net { enum Family { - UNSPEC = AF_UNSPEC, - INET = AF_INET, - INET6 = AF_INET6, - UNIF = AF_UNIX + UNSPEC, + INET, + INET6, + UNIX }; +int family_to_sys(Family); +Family family_from_sys(int); + } // namespace Net } // namespace Msp diff --git a/source/resolve.cpp b/source/resolve.cpp index 31b15fb..3896db7 100644 --- a/source/resolve.cpp +++ b/source/resolve.cpp @@ -37,7 +37,7 @@ SockAddr *resolve(const string &s, Family family) host = s; } - addrinfo hints = {0, family, 0, 0, 0, 0, 0, 0}; + addrinfo hints = { 0, family_to_sys(family), 0, 0, 0, 0, 0, 0 }; addrinfo *res; const char *chost = (host.empty() ? 0 : host.c_str()); const char *cserv = (serv.empty() ? 0 : serv.c_str()); diff --git a/source/socket.cpp b/source/socket.cpp index e91b684..8fa910c 100644 --- a/source/socket.cpp +++ b/source/socket.cpp @@ -66,7 +66,7 @@ Socket::Socket(Family af, int type, int proto): local_addr(0), peer_addr(0) { - priv->handle = socket(af, type, proto); + priv->handle = socket(family_to_sys(af), type, proto); #ifdef WIN32 *priv->event = CreateEvent(0, false, false, 0);