- win32 winsock bugfixes causing havok and grief for win32 users (corrupt winsock stack due to extra call to wsacleanup)

This commit is contained in:
Mark Vejvoda 2011-01-17 23:45:09 +00:00
parent d8e28fbf90
commit 9ba8668751
6 changed files with 31 additions and 11 deletions

View File

@ -695,7 +695,9 @@ void MenuStateMasterserver::simpleTask(BaseThread *callingThread) {
if(announcementURL != "") { if(announcementURL != "") {
safeMutex.ReleaseLock(true); safeMutex.ReleaseLock(true);
std::string announcementTxt = SystemFlags::getHTTP(announcementURL); CURL *handle = SystemFlags::initHTTP();
std::string announcementTxt = SystemFlags::getHTTP(announcementURL,handle);
SystemFlags::cleanupHTTP(&handle);
if(callingThread->getQuitStatus() == true) { if(callingThread->getQuitStatus() == true) {
return; return;
} }
@ -728,7 +730,9 @@ void MenuStateMasterserver::simpleTask(BaseThread *callingThread) {
//printf("\nversionURL=%s\n",versionURL.c_str()); //printf("\nversionURL=%s\n",versionURL.c_str());
if(versionURL != "") { if(versionURL != "") {
safeMutex.ReleaseLock(true); safeMutex.ReleaseLock(true);
std::string versionTxt = SystemFlags::getHTTP(versionURL); CURL *handle = SystemFlags::initHTTP();
std::string versionTxt = SystemFlags::getHTTP(versionURL,handle);
SystemFlags::cleanupHTTP(&handle);
if(callingThread->getQuitStatus() == true) { if(callingThread->getQuitStatus() == true) {
return; return;
} }
@ -769,7 +773,9 @@ void MenuStateMasterserver::simpleTask(BaseThread *callingThread) {
if(Config::getInstance().getString("Masterserver","") != "") { if(Config::getInstance().getString("Masterserver","") != "") {
safeMutex.ReleaseLock(true); safeMutex.ReleaseLock(true);
std::string localServerInfoString = SystemFlags::getHTTP(Config::getInstance().getString("Masterserver") + "showServersForGlest.php"); CURL *handle = SystemFlags::initHTTP();
std::string localServerInfoString = SystemFlags::getHTTP(Config::getInstance().getString("Masterserver") + "showServersForGlest.php",handle);
SystemFlags::cleanupHTTP(&handle);
if(callingThread->getQuitStatus() == true) { if(callingThread->getQuitStatus() == true) {
return; return;
} }

View File

@ -104,7 +104,7 @@ class Socket : public SimpleTaskCallbackInterface {
protected: protected:
#ifdef WIN32 #ifdef WIN32
SocketManager wsaManager; static SocketManager wsaManager;
#endif #endif
PLATFORM_SOCKET sock; PLATFORM_SOCKET sock;
time_t lastDebugEvent; time_t lastDebugEvent;

View File

@ -396,7 +396,7 @@ socket_t ftpCreateServerSocket(int portNumber)
if(bind(theServer, (struct sockaddr *)&serverinfo, len)) if(bind(theServer, (struct sockaddr *)&serverinfo, len))
{ {
if(VERBOSE_MODE_ENABLED) printf("\ERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d\n",theServer); if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d\n",theServer);
ftpUntrackSocket(theServer); ftpUntrackSocket(theServer);
ftpCloseSocket(&theServer); ftpCloseSocket(&theServer);
@ -405,7 +405,7 @@ socket_t ftpCreateServerSocket(int portNumber)
if(listen(theServer, 100)) if(listen(theServer, 100))
{ {
if(VERBOSE_MODE_ENABLED) printf("\ERROR In ftpCreateServerSocket listen FAILED about to close listener socket = %d\n",theServer); if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket listen FAILED about to close listener socket = %d\n",theServer);
ftpUntrackSocket(theServer); ftpUntrackSocket(theServer);
ftpCloseSocket(&theServer); ftpCloseSocket(&theServer);

View File

@ -39,6 +39,7 @@ ip_t ownIp;
LOCAL fd_set watchedSockets; LOCAL fd_set watchedSockets;
LOCAL fd_set signaledSockets; LOCAL fd_set signaledSockets;
LOCAL int maxSockNr; LOCAL int maxSockNr;
int wsaInitCount=0;
void ftpArchInit() void ftpArchInit()
{ {
@ -46,12 +47,19 @@ void ftpArchInit()
ownIp = 0; ownIp = 0;
maxSockNr = 0; maxSockNr = 0;
FD_ZERO(&watchedSockets); FD_ZERO(&watchedSockets);
if(VERBOSE_MODE_ENABLED) printf("Feathery calling WSAStartup...\n");
WSAStartup(MAKEWORD(2, 0),&wsaData); WSAStartup(MAKEWORD(2, 0),&wsaData);
wsaInitCount++;
} }
void ftpArchCleanup(void) void ftpArchCleanup(void)
{ {
WSACleanup(); // WINSOCK freigeben if(VERBOSE_MODE_ENABLED) printf("Feathery calling WSACleanup...[%d]\n",wsaInitCount);
if(wsaInitCount > 0)
{
WSACleanup(); // WINSOCK freigeben
wsaInitCount--;
}
} }
int ftpGetLocalTime(ftpTime_S *t) int ftpGetLocalTime(ftpTime_S *t)
@ -319,7 +327,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
myAddr.sin_port = htons(passivePort); myAddr.sin_port = htons(passivePort);
//myAddr.sin_port = htons(ftpGetPassivePort() + sessionId); //myAddr.sin_port = htons(ftpGetPassivePort() + sessionId);
if(setsockopt(dataSocket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) if(setsockopt(dataSocket, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)))
{ {
if(VERBOSE_MODE_ENABLED) printf("PASSIVE CONNECTION In ftpEstablishDataConnection setsockopt failed about to Close socket = %d, for sessionId = %d\n",dataSocket, sessionId); if(VERBOSE_MODE_ENABLED) printf("PASSIVE CONNECTION In ftpEstablishDataConnection setsockopt failed about to Close socket = %d, for sessionId = %d\n",dataSocket, sessionId);
@ -428,7 +436,7 @@ socket_t ftpCreateServerSocket(int portNumber)
if(bind(theServer, (struct sockaddr *)&serverinfo, len)) if(bind(theServer, (struct sockaddr *)&serverinfo, len))
{ {
if(VERBOSE_MODE_ENABLED) printf("\ERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d\n",theServer); if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket bind FAILED about to close listener socket = %d\n",theServer);
ftpUntrackSocket(theServer); ftpUntrackSocket(theServer);
ftpCloseSocket(&theServer); ftpCloseSocket(&theServer);
@ -437,7 +445,7 @@ socket_t ftpCreateServerSocket(int portNumber)
if(listen(theServer, 100)) if(listen(theServer, 100))
{ {
if(VERBOSE_MODE_ENABLED) printf("\ERROR In ftpCreateServerSocket listen FAILED about to close listener socket = %d\n",theServer); if(VERBOSE_MODE_ENABLED) printf("\nERROR In ftpCreateServerSocket listen FAILED about to close listener socket = %d\n",theServer);
ftpUntrackSocket(theServer); ftpUntrackSocket(theServer);
ftpCloseSocket(&theServer); ftpCloseSocket(&theServer);

View File

@ -214,17 +214,20 @@ bool UPNP_Tools::enabledUPNP = false;
return acErrorBuffer; return acErrorBuffer;
} }
//SocketManager Socket::socketManager; // keeps in scope for duration of the application
SocketManager Socket::wsaManager;
SocketManager::SocketManager() { SocketManager::SocketManager() {
WSADATA wsaData; WSADATA wsaData;
WORD wVersionRequested = MAKEWORD(2, 0); WORD wVersionRequested = MAKEWORD(2, 0);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("SocketManager calling WSAStartup...\n");
WSAStartup(wVersionRequested, &wsaData); WSAStartup(wVersionRequested, &wsaData);
//dont throw exceptions here, this is a static initializacion //dont throw exceptions here, this is a static initializacion
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Winsock initialized.\n"); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Winsock initialized.\n");
} }
SocketManager::~SocketManager() { SocketManager::~SocketManager() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("SocketManager calling WSACleanup...\n");
WSACleanup(); WSACleanup();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Winsock cleanup complete.\n"); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Winsock cleanup complete.\n");
} }

View File

@ -171,6 +171,9 @@ CURL *SystemFlags::initHTTP() {
//printf("In [%s::%s Line %d] curl_global_init called and returned: result %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,result,curl_easy_strerror(result)); //printf("In [%s::%s Line %d] curl_global_init called and returned: result %d [%s]\n",__FILE__,__FUNCTION__,__LINE__,result,curl_easy_strerror(result));
} }
CURL *handle = curl_easy_init(); CURL *handle = curl_easy_init();
if(handle == NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] ERROR handle = NULL\n",__FILE__,__FUNCTION__,__LINE__);
}
curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1);
return handle; return handle;
} }