From 9ec36cae77868aea2c5bc3c36e9349809d7a6b58 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 4 Sep 2011 11:14:55 -0700 Subject: [PATCH] fixes for windows --- mc_buffer.cpp | 4 ++-- mc_socket.cpp | 26 +++++++++++++++++++++++--- metacall.hpp | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mc_buffer.cpp b/mc_buffer.cpp index 51b41d5..cf9c3bc 100644 --- a/mc_buffer.cpp +++ b/mc_buffer.cpp @@ -87,11 +87,11 @@ void Buffer::setData(const void* data, int bytes) { } const void* Buffer::data() const { - return &data_[0]; + return bytes() == 0 ? NULL : &data_[0]; } void* Buffer::data() { - return &data_[0]; + return bytes() == 0 ? NULL : &data_[0]; } int Buffer::bytes() const { diff --git a/mc_socket.cpp b/mc_socket.cpp index ea2ab86..148832f 100644 --- a/mc_socket.cpp +++ b/mc_socket.cpp @@ -29,16 +29,36 @@ namespace metacall { +namespace { + + // // Constants // -namespace { - - const int SOCKET_INVALID = -1; +// +// Winsock +// + +#ifdef _WIN32 + +struct WsaScope { + WsaScope() { + WSAData data; + WSAStartup(MAKEWORD(2, 2), &data); + } + + ~WsaScope() { + WSACleanup(); + } +} wsa; + +#endif + + } diff --git a/metacall.hpp b/metacall.hpp index 99a47d2..73c5de9 100644 --- a/metacall.hpp +++ b/metacall.hpp @@ -31,6 +31,7 @@ #ifdef _WIN32 #pragma comment(lib, "ws2_32.lib") + #define NOMINMAX #include #else #include