From: Mikko Rasa Date: Mon, 8 Oct 2012 20:38:31 +0000 (+0300) Subject: Hide the set_option and get_option functions in socket_private.h X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3840d5d193327059b84406ee6b0ba263f5ef2401;p=libs%2Fnet.git Hide the set_option and get_option functions in socket_private.h These depend on a system-specific type, so they can't be in a public header. --- diff --git a/source/net/socket.cpp b/source/net/socket.cpp index 7591977..2378207 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -129,30 +129,31 @@ void Socket::set_timeout(const Time::TimeDelta &timeout) { #ifndef WIN32 timeval tv = Time::rawtime_to_timeval(timeout.raw()); - set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval)); - set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval)); + priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval)); + priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval)); #else DWORD msecs = static_cast(timeout/Time::msec); - set_option(SOL_SOCKET, SO_RCVTIMEO, &msecs, sizeof(DWORD)); - set_option(SOL_SOCKET, SO_SNDTIMEO, &msecs, sizeof(DWORD)); + priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &msecs, sizeof(DWORD)); + priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &msecs, sizeof(DWORD)); #endif } -int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) + +int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen) { #ifdef WIN32 - return setsockopt(priv->handle, level, optname, reinterpret_cast(optval), optlen); + return setsockopt(handle, level, optname, reinterpret_cast(optval), optlen); #else - return setsockopt(priv->handle, level, optname, optval, optlen); + return setsockopt(handle, level, optname, optval, optlen); #endif } -int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) const +int Socket::Private::get_option(int level, int optname, void *optval, socklen_t *optlen) { #ifdef WIN32 - return getsockopt(priv->handle, level, optname, reinterpret_cast(optval), optlen); + return getsockopt(handle, level, optname, reinterpret_cast(optval), optlen); #else - return getsockopt(priv->handle, level, optname, optval, optlen); + return getsockopt(handle, level, optname, optval, optlen); #endif } diff --git a/source/net/socket.h b/source/net/socket.h index f975884..c830930 100644 --- a/source/net/socket.h +++ b/source/net/socket.h @@ -9,11 +9,6 @@ namespace Msp { namespace Net { -#ifdef WIN32 -typedef int socklen_t; -#endif - - class bad_socket_state: public std::logic_error { public: @@ -45,9 +40,6 @@ public: const SockAddr &get_local_address() const; void set_timeout(const Time::TimeDelta &); -protected: - int set_option(int, int, const void *, socklen_t); - int get_option(int, int, void *, socklen_t *) const; }; } // namespace Net diff --git a/source/net/socket_private.h b/source/net/socket_private.h index 83cc369..fc8b23b 100644 --- a/source/net/socket_private.h +++ b/source/net/socket_private.h @@ -7,6 +7,10 @@ namespace Msp { namespace Net { +#ifdef WIN32 +typedef int socklen_t; +#endif + struct Socket::Private { #ifdef WIN32 @@ -18,6 +22,9 @@ struct Socket::Private /* On POSIX platforms this is the same as the handle. This might seem strange but it allows the same syntax on both POSIX and Windows. */ IO::Handle event; + + int set_option(int, int, const void *, socklen_t); + int get_option(int, int, void *, socklen_t *); }; } // namespace Net diff --git a/source/net/streamsocket.cpp b/source/net/streamsocket.cpp index 8a26245..3da0cc3 100644 --- a/source/net/streamsocket.cpp +++ b/source/net/streamsocket.cpp @@ -90,7 +90,7 @@ bool StreamSocket::poll_connect(const Time::TimeDelta &timeout) int err; socklen_t len = sizeof(int); - get_option(SOL_SOCKET, SO_ERROR, &err, &len); + priv->get_option(SOL_SOCKET, SO_ERROR, &err, &len); if(err!=0) { @@ -119,7 +119,7 @@ void StreamSocket::on_event(IO::PollEvent ev) { int err; socklen_t len = sizeof(err); - get_option(SOL_SOCKET, SO_ERROR, &err, &len); + priv->get_option(SOL_SOCKET, SO_ERROR, &err, &len); connecting = false; connected = (err==0);