From 136c9eec2b72bfad4788908de5552fbd62216148 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 14 Sep 2016 14:26:50 +0300 Subject: [PATCH] Use the correct #ifdef for Windows --- source/net/clientsocket.cpp | 4 ++-- source/net/constants.cpp | 2 +- source/net/datagramsocket.cpp | 10 +++++----- source/net/inet.cpp | 2 +- source/net/inet6.cpp | 2 +- source/net/resolve.cpp | 4 ++-- source/net/sockaddr_private.h | 4 ++-- source/net/socket.cpp | 18 +++++++++--------- source/net/socket_private.h | 4 ++-- source/net/streamserversocket.cpp | 4 ++-- source/net/streamsocket.cpp | 14 +++++++------- source/net/unix.cpp | 10 +++++----- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/source/net/clientsocket.cpp b/source/net/clientsocket.cpp index d28d0e9..cbf18e5 100644 --- a/source/net/clientsocket.cpp +++ b/source/net/clientsocket.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -36,7 +36,7 @@ void ClientSocket::shutdown(IO::Mode m) { int how; m = m&IO::M_RDWR; -#ifdef WIN32 +#ifdef _WIN32 if(m==IO::M_READ) how = SD_RECEIVE; else if(m==IO::M_WRITE) diff --git a/source/net/constants.cpp b/source/net/constants.cpp index e57897d..c98945c 100644 --- a/source/net/constants.cpp +++ b/source/net/constants.cpp @@ -1,5 +1,5 @@ #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include diff --git a/source/net/datagramsocket.cpp b/source/net/datagramsocket.cpp index 664c265..0e405d6 100644 --- a/source/net/datagramsocket.cpp +++ b/source/net/datagramsocket.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #endif #include @@ -15,7 +15,7 @@ namespace Net { DatagramSocket::DatagramSocket(Family f, int p): ClientSocket(f, SOCK_DGRAM, p) { -#ifdef WIN32 +#ifdef _WIN32 WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); #endif set_events(IO::P_INPUT); @@ -28,7 +28,7 @@ bool DatagramSocket::connect(const SockAddr &addr) int err = ::connect(priv->handle, reinterpret_cast(&sa.addr), sa.size); if(err==-1) { -#ifdef WIN32 +#ifdef _WIN32 throw system_error("connect", WSAGetLastError()); #else throw system_error("connect"); @@ -62,7 +62,7 @@ unsigned DatagramSocket::sendto(const char *buf, unsigned size, const SockAddr & return 0; else { -#ifdef WIN32 +#ifdef _WIN32 throw system_error("sendto", WSAGetLastError()); #else throw system_error("sendto"); @@ -86,7 +86,7 @@ unsigned DatagramSocket::recvfrom(char *buf, unsigned size, SockAddr *&from_addr return 0; else { -#ifdef WIN32 +#ifdef _WIN32 throw system_error("recvfrom", WSAGetLastError()); #else throw system_error("recvfrom"); diff --git a/source/net/inet.cpp b/source/net/inet.cpp index c78ea61..f428492 100644 --- a/source/net/inet.cpp +++ b/source/net/inet.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include diff --git a/source/net/inet6.cpp b/source/net/inet6.cpp index 79da1d2..f33ed18 100644 --- a/source/net/inet6.cpp +++ b/source/net/inet6.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #include #else diff --git a/source/net/resolve.cpp b/source/net/resolve.cpp index 992973a..ce47b51 100644 --- a/source/net/resolve.cpp +++ b/source/net/resolve.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #define _WIN32_WINNT 0x0501 #include #else @@ -70,7 +70,7 @@ SockAddr *resolve(const string &host, const string &serv, Family family) return addr; } else -#ifdef WIN32 +#ifdef _WIN32 throw system_error("getaddrinfo", WSAGetLastError()); #else throw system_error("getaddrinfo", gai_strerror(err)); diff --git a/source/net/sockaddr_private.h b/source/net/sockaddr_private.h index 16af063..4aa9231 100644 --- a/source/net/sockaddr_private.h +++ b/source/net/sockaddr_private.h @@ -1,7 +1,7 @@ #ifndef MSP_NET_SOCKADDR_PRIVATE_H_ #define MSP_NET_SOCKADDR_PRIVATE_H_ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -14,7 +14,7 @@ namespace Net { struct SockAddr::SysAddr { struct sockaddr_storage addr; -#ifdef WIN32 +#ifdef _WIN32 int size; #else socklen_t size; diff --git a/source/net/socket.cpp b/source/net/socket.cpp index 7c16217..1a5898b 100644 --- a/source/net/socket.cpp +++ b/source/net/socket.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -18,7 +18,7 @@ namespace { -#ifdef WIN32 +#ifdef _WIN32 class WinSockHelper { public: @@ -56,7 +56,7 @@ Socket::Socket(const Private &p): 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; @@ -71,7 +71,7 @@ Socket::Socket(Family af, int type, int proto): 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; @@ -80,7 +80,7 @@ Socket::Socket(Family af, int type, int proto): Socket::~Socket() { -#ifdef WIN32 +#ifdef _WIN32 closesocket(priv->handle); CloseHandle(*priv->event); #else @@ -97,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 @@ -133,7 +133,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)); @@ -147,7 +147,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); @@ -156,7 +156,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); diff --git a/source/net/socket_private.h b/source/net/socket_private.h index fc8b23b..995ead0 100644 --- a/source/net/socket_private.h +++ b/source/net/socket_private.h @@ -7,13 +7,13 @@ namespace Msp { namespace Net { -#ifdef WIN32 +#ifdef _WIN32 typedef int socklen_t; #endif struct Socket::Private { -#ifdef WIN32 +#ifdef _WIN32 SOCKET handle; #else int handle; diff --git a/source/net/streamserversocket.cpp b/source/net/streamserversocket.cpp index 8039ec9..e408dce 100644 --- a/source/net/streamserversocket.cpp +++ b/source/net/streamserversocket.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #endif #include @@ -29,7 +29,7 @@ void StreamServerSocket::listen(const SockAddr &addr, unsigned backlog) if(err==-1) throw system_error("listen"); -#ifdef WIN32 +#ifdef _WIN32 WSAEventSelect(priv->handle, *priv->event, FD_ACCEPT); #endif set_events(IO::P_INPUT); diff --git a/source/net/streamsocket.cpp b/source/net/streamsocket.cpp index 85f2b00..da5069c 100644 --- a/source/net/streamsocket.cpp +++ b/source/net/streamsocket.cpp @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -18,7 +18,7 @@ namespace Net { StreamSocket::StreamSocket(const Private &p, const SockAddr &paddr): ClientSocket(p, paddr) { -#ifdef WIN32 +#ifdef _WIN32 WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); #endif set_events(IO::P_INPUT); @@ -36,7 +36,7 @@ bool StreamSocket::connect(const SockAddr &addr) SockAddr::SysAddr sa = addr.to_sys(); int err = ::connect(priv->handle, reinterpret_cast(&sa.addr), sa.size); -#ifdef WIN32 +#ifdef _WIN32 if(err==SOCKET_ERROR) { int err_code = WSAGetLastError(); @@ -73,7 +73,7 @@ bool StreamSocket::connect(const SockAddr &addr) if(err==0) { connected = true; -#ifdef WIN32 +#ifdef _WIN32 WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); #endif set_events(IO::P_INPUT); @@ -100,14 +100,14 @@ bool StreamSocket::poll_connect(const Time::TimeDelta &timeout) if(err!=0) { set_events(IO::P_NONE); -#ifdef WIN32 +#ifdef _WIN32 throw system_error("connect", WSAGetLastError()); #else throw system_error("connect"); #endif } -#ifdef WIN32 +#ifdef _WIN32 WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); #endif set_events(IO::P_INPUT); @@ -142,7 +142,7 @@ void StreamSocket::on_event(IO::PollEvent ev) peer_addr = 0; } -#ifdef WIN32 +#ifdef _WIN32 WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE); #endif set_events((err==0) ? IO::P_INPUT : IO::P_NONE); diff --git a/source/net/unix.cpp b/source/net/unix.cpp index cd1f414..9d8cf27 100644 --- a/source/net/unix.cpp +++ b/source/net/unix.cpp @@ -1,5 +1,5 @@ #include -#ifndef WIN32 +#ifndef _WIN32 #include #endif #include "sockaddr_private.h" @@ -13,7 +13,7 @@ namespace Net { UnixAddr::UnixAddr(): abstract(false) { -#ifdef WIN32 +#ifdef _WIN32 throw logic_error("no unix sockets on windows"); #endif } @@ -21,7 +21,7 @@ UnixAddr::UnixAddr(): UnixAddr::UnixAddr(const SysAddr &sa): abstract(false) { -#ifdef WIN32 +#ifdef _WIN32 (void)sa; throw logic_error("no unix sockets on windows"); #else @@ -38,7 +38,7 @@ UnixAddr::UnixAddr(const string &p, bool a): path(p), abstract(a) { -#ifdef WIN32 +#ifdef _WIN32 throw logic_error("no unix sockets on windows"); #else if(sizeof(sa_family_t)+path.size()+1>sizeof(sockaddr_storage)) @@ -49,7 +49,7 @@ UnixAddr::UnixAddr(const string &p, bool a): SockAddr::SysAddr UnixAddr::to_sys() const { SysAddr sa; -#ifndef WIN32 +#ifndef _WIN32 sa.size = sizeof(sa_family_t); if(!path.empty()) sa.size += path.size()+1; -- 2.43.0