X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fnet%2Fsocket.cpp;h=7c162178eb1a822c43d9167d741bba67131674f0;hp=75919777e6cb0c256d3a9dea1bf0ded6bd3587b4;hb=fa637ffb18421300e401a782d28dd729a3960ac4;hpb=de95d7d024ebf9d18721579f52b98311c853ea67 diff --git a/source/net/socket.cpp b/source/net/socket.cpp index 7591977..7c16217 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -1,4 +1,6 @@ -#ifndef WIN32 +#ifdef WIN32 +#include +#else #include #include #include @@ -46,6 +48,8 @@ Socket::Socket(const Private &p): priv(new Private), local_addr(0) { + mode = IO::M_RDWR; + priv->handle = p.handle; SockAddr::SysAddr sa; @@ -63,6 +67,8 @@ Socket::Socket(Family af, int type, int proto): priv(new Private), local_addr(0) { + mode = IO::M_RDWR; + priv->handle = socket(family_to_sys(af), type, proto); #ifdef WIN32 @@ -129,30 +135,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 }