From ef2f33c700a9f559648089a5314638f9c73d3589 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 14 Jan 2009 21:09:21 +0000 Subject: Gettin' closer. --- src/socket.cpp | 6 ++++++ src/win32_compatibility.cpp | 10 ++++++++++ src/win32_compatibility.h | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/socket.cpp b/src/socket.cpp index 3870a59..3458b45 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -35,11 +35,17 @@ Bu::Socket::Socket( int nSocket ) : nSocket( nSocket ), bActive( true ) { +#ifdef WIN32 + DynamicWinsock32::Winsock2::getInstance(); +#endif setAddress(); } Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) { +#ifdef WIN32 + DynamicWinsock32::Winsock2::getInstance(); +#endif bActive = false; /* Create the socket. */ diff --git a/src/win32_compatibility.cpp b/src/win32_compatibility.cpp index 083925b..e7710e5 100644 --- a/src/win32_compatibility.cpp +++ b/src/win32_compatibility.cpp @@ -350,5 +350,15 @@ int DynamicWinsock2::DYN_FD_ISSET(SOCKET s, fd_set *set) return out; } +DynamicWinsock2::Winsock2::Winsock2() +{ + DynamicWinsock2::WSAStartup( MAKEWORD(2, 2), &wsaData ); +} + +DynamicWinsock2::Winsock2::~Winsock2() +{ + DynamicWinsock2::WSACleanup(); +} + #endif diff --git a/src/win32_compatibility.h b/src/win32_compatibility.h index 72cb4f7..2fe740a 100644 --- a/src/win32_compatibility.h +++ b/src/win32_compatibility.h @@ -24,7 +24,8 @@ extern "C" } #endif -#include "fstring.h" +#include "bu/fstring.h" +#include "bu/singleton.h" #ifndef TEMP_FAILURE_RETRY #define TEMP_FAILURE_RETRY(expression) \ @@ -65,6 +66,18 @@ namespace DynamicWinsock2 int recv( SOCKET s, char *buf, int len, int flags ); int send( SOCKET s, const char *buf, int len, int flags ); int DYN_FD_ISSET(SOCKET s, fd_set *set); + + class Winsock2 : public Bu::Singleton + { + friend class Bu::Singleton; + private: + Winsock2(); + virtual ~Winsock2(); + + WSADATA wsaData; + + public: + } }; #endif /* WIN32 */ -- cgit v1.2.3