• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

WSAStartupSingleton.cpp

Go to the documentation of this file.
00001 #include "WSAStartupSingleton.h"
00002 
00003 #if defined(_XBOX) || defined(X360)
00004                                                                                              
00005 #elif defined(_WIN32)
00006 #include <winsock2.h>
00007 #include <ws2tcpip.h>
00008 #endif
00009 #include "RakNetDefines.h"
00010 #include <stdio.h>
00011 
00012 int WSAStartupSingleton::refCount=0;
00013 
00014 WSAStartupSingleton::WSAStartupSingleton() {}
00015 WSAStartupSingleton::~WSAStartupSingleton() {}
00016 void WSAStartupSingleton::AddRef(void)
00017 {
00018 #ifdef _WIN32
00019 
00020         refCount++;
00021         
00022         if (refCount!=1)
00023                 return;
00024 
00025 #if defined(_XBOX) || defined(X360)
00026                
00027 #endif
00028 
00029         WSADATA winsockInfo;
00030         if ( WSAStartup( MAKEWORD( 2, 2 ), &winsockInfo ) != 0 )
00031         {
00032 #if !defined(_XBOX) && !defined(X360) && defined(_DEBUG)
00033                 DWORD dwIOError = GetLastError();
00034                 LPVOID messageBuffer;
00035                 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
00036                         NULL, dwIOError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),  // Default language
00037                         ( LPTSTR ) & messageBuffer, 0, NULL );
00038                 // something has gone wrong here...
00039                 RAKNET_DEBUG_PRINTF( "WSAStartup failed:Error code - %d\n%s", dwIOError, messageBuffer );
00040                 //Free the buffer.
00041                 LocalFree( messageBuffer );
00042 #endif
00043         }
00044 
00045 #endif
00046 }
00047 void WSAStartupSingleton::Deref(void)
00048 {
00049 #ifdef _WIN32
00050         if (refCount==0)
00051                 return;
00052                 
00053         if (refCount>1)
00054         {
00055                 refCount--;
00056                 return;
00057         }
00058         
00059         WSACleanup();
00060 
00061 #if defined(_XBOX) || defined(X360)
00062                 
00063 #endif
00064 
00065         
00066         refCount=0;
00067 #endif
00068 }

Generated on Thu Sep 30 2010 01:27:29 for RakNet by  doxygen 1.7.1