-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#else
#include <cerrno>
{
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)
#include <stdexcept>
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#endif
#include <cerrno>
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);
int err = ::connect(priv->handle, reinterpret_cast<sockaddr *>(&sa.addr), sa.size);
if(err==-1)
{
-#ifdef WIN32
+#ifdef _WIN32
throw system_error("connect", WSAGetLastError());
#else
throw system_error("connect");
return 0;
else
{
-#ifdef WIN32
+#ifdef _WIN32
throw system_error("sendto", WSAGetLastError());
#else
throw system_error("sendto");
return 0;
else
{
-#ifdef WIN32
+#ifdef _WIN32
throw system_error("recvfrom", WSAGetLastError());
#else
throw system_error("recvfrom");
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#else
#include <netinet/in.h>
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
-#ifdef WIN32
+#ifdef _WIN32
#define _WIN32_WINNT 0x0501
#include <ws2tcpip.h>
#else
return addr;
}
else
-#ifdef WIN32
+#ifdef _WIN32
throw system_error("getaddrinfo", WSAGetLastError());
#else
throw system_error("getaddrinfo", gai_strerror(err));
#ifndef MSP_NET_SOCKADDR_PRIVATE_H_
#define MSP_NET_SOCKADDR_PRIVATE_H_
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
struct SockAddr::SysAddr
{
struct sockaddr_storage addr;
-#ifdef WIN32
+#ifdef _WIN32
int size;
#else
socklen_t size;
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#else
#include <cerrno>
namespace {
-#ifdef WIN32
+#ifdef _WIN32
class WinSockHelper
{
public:
getsockname(priv->handle, reinterpret_cast<sockaddr *>(&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;
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;
Socket::~Socket()
{
-#ifdef WIN32
+#ifdef _WIN32
closesocket(priv->handle);
CloseHandle(*priv->event);
#else
if(b)
mode = (mode|IO::M_NONBLOCK);
-#ifdef WIN32
+#ifdef _WIN32
u_long flag = !b;
ioctlsocket(priv->handle, FIONBIO, &flag);
#else
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));
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<const char *>(optval), optlen);
#else
return setsockopt(handle, level, optname, optval, optlen);
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<char *>(optval), optlen);
#else
return getsockopt(handle, level, optname, optval, optlen);
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;
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#endif
#include <cerrno>
if(err==-1)
throw system_error("listen");
-#ifdef WIN32
+#ifdef _WIN32
WSAEventSelect(priv->handle, *priv->event, FD_ACCEPT);
#endif
set_events(IO::P_INPUT);
-#ifdef WIN32
+#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
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);
SockAddr::SysAddr sa = addr.to_sys();
int err = ::connect(priv->handle, reinterpret_cast<sockaddr *>(&sa.addr), sa.size);
-#ifdef WIN32
+#ifdef _WIN32
if(err==SOCKET_ERROR)
{
int err_code = WSAGetLastError();
if(err==0)
{
connected = true;
-#ifdef WIN32
+#ifdef _WIN32
WSAEventSelect(priv->handle, *priv->event, FD_READ|FD_CLOSE);
#endif
set_events(IO::P_INPUT);
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);
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);
#include <stdexcept>
-#ifndef WIN32
+#ifndef _WIN32
#include <sys/un.h>
#endif
#include "sockaddr_private.h"
UnixAddr::UnixAddr():
abstract(false)
{
-#ifdef WIN32
+#ifdef _WIN32
throw logic_error("no unix sockets on windows");
#endif
}
UnixAddr::UnixAddr(const SysAddr &sa):
abstract(false)
{
-#ifdef WIN32
+#ifdef _WIN32
(void)sa;
throw logic_error("no unix sockets on windows");
#else
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))
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;