X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fnet%2Fsocket.cpp;h=031d077c44dcc194a095455d06dde3def3a62ccd;hp=2378207048c9a9a91395eca79227ea6088c5a56b;hb=6f6845971a21c2d7e04b87925f5e657f0f20ca0d;hpb=3840d5d193327059b84406ee6b0ba263f5ef2401 diff --git a/source/net/socket.cpp b/source/net/socket.cpp index 2378207..031d077 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -1,4 +1,6 @@ -#ifndef WIN32 +#ifdef _WIN32 +#include +#else #include #include #include @@ -16,7 +18,7 @@ namespace { -#ifdef WIN32 +#ifdef _WIN32 class WinSockHelper { public: @@ -46,13 +48,15 @@ Socket::Socket(const Private &p): priv(new Private), local_addr(0) { + mode = IO::M_RDWR; + priv->handle = p.handle; SockAddr::SysAddr sa; getsockname(priv->handle, reinterpret_cast(&sa.addr), &sa.size); local_addr = SockAddr::new_from_sys(sa); -#ifdef WIN32 +#ifdef _WIN32 *priv->event = CreateEvent(0, false, false, 0); #else *priv->event = priv->handle; @@ -63,9 +67,11 @@ 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 +#ifdef _WIN32 *priv->event = CreateEvent(0, false, false, 0); #else *priv->event = priv->handle; @@ -74,7 +80,7 @@ Socket::Socket(Family af, int type, int proto): Socket::~Socket() { -#ifdef WIN32 +#ifdef _WIN32 closesocket(priv->handle); CloseHandle(*priv->event); #else @@ -91,7 +97,7 @@ void Socket::set_block(bool b) if(b) mode = (mode|IO::M_NONBLOCK); -#ifdef WIN32 +#ifdef _WIN32 u_long flag = !b; ioctlsocket(priv->handle, FIONBIO, &flag); #else @@ -105,7 +111,6 @@ const IO::Handle &Socket::get_event_handle() return priv->event; } - void Socket::bind(const SockAddr &addr) { SockAddr::SysAddr sa = addr.to_sys(); @@ -127,7 +132,7 @@ const SockAddr &Socket::get_local_address() const void Socket::set_timeout(const Time::TimeDelta &timeout) { -#ifndef WIN32 +#ifndef _WIN32 timeval tv = Time::rawtime_to_timeval(timeout.raw()); priv->set_option(SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval)); priv->set_option(SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(timeval)); @@ -141,7 +146,7 @@ void Socket::set_timeout(const Time::TimeDelta &timeout) int Socket::Private::set_option(int level, int optname, const void *optval, socklen_t optlen) { -#ifdef WIN32 +#ifdef _WIN32 return setsockopt(handle, level, optname, reinterpret_cast(optval), optlen); #else return setsockopt(handle, level, optname, optval, optlen); @@ -150,7 +155,7 @@ int Socket::Private::set_option(int level, int optname, const void *optval, sock int Socket::Private::get_option(int level, int optname, void *optval, socklen_t *optlen) { -#ifdef WIN32 +#ifdef _WIN32 return getsockopt(handle, level, optname, reinterpret_cast(optval), optlen); #else return getsockopt(handle, level, optname, optval, optlen);