mirror of
https://github.com/glest/glest-source.git
synced 2025-08-17 21:51:17 +02:00
- attempt to make accepting socket connections and dealing with certain connection problems more stable
This commit is contained in:
@@ -1483,6 +1483,9 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError
|
|||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] SOCKET appears to be invalid [%d]\n",__FILE__,__FUNCTION__,__LINE__,sock);
|
||||||
|
}
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
int lastSocketError = getLastSocketError();
|
int lastSocketError = getLastSocketError();
|
||||||
@@ -1535,6 +1538,9 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError
|
|||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 SOCKET appears to be invalid [%d]\n",__FILE__,__FUNCTION__,__LINE__,sock);
|
||||||
|
}
|
||||||
|
|
||||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||||
|
|
||||||
@@ -1545,7 +1551,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError
|
|||||||
int iErr = lastSocketError;
|
int iErr = lastSocketError;
|
||||||
disconnectSocket();
|
disconnectSocket();
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str());
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data for socket [%d], err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,socket,err,getLastSocketErrorFormattedText(&iErr).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2250,11 +2256,15 @@ Socket *ServerSocket::accept(bool errorOnFail) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PLATFORM_SOCKET newSock=0;
|
||||||
|
char client_host[100]="";
|
||||||
|
const int max_attempts = 100;
|
||||||
|
for(int attempt = 0; attempt < max_attempts; ++attempt) {
|
||||||
struct sockaddr_in cli_addr;
|
struct sockaddr_in cli_addr;
|
||||||
socklen_t clilen = sizeof(cli_addr);
|
socklen_t clilen = sizeof(cli_addr);
|
||||||
char client_host[100]="";
|
client_host[0]='\0';
|
||||||
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
if(isSocketValid(&newSock) == false) {
|
if(isSocketValid(&newSock) == false) {
|
||||||
@@ -2264,8 +2274,13 @@ Socket *ServerSocket::accept(bool errorOnFail) {
|
|||||||
|
|
||||||
int lastSocketError = getLastSocketError();
|
int lastSocketError = getLastSocketError();
|
||||||
if(lastSocketError == PLATFORM_SOCKET_TRY_AGAIN) {
|
if(lastSocketError == PLATFORM_SOCKET_TRY_AGAIN) {
|
||||||
|
if(attempt+1 >= max_attempts) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
sleep(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(errorOnFail == true) {
|
if(errorOnFail == true) {
|
||||||
throwException(szBuf);
|
throwException(szBuf);
|
||||||
}
|
}
|
||||||
@@ -2283,17 +2298,19 @@ Socket *ServerSocket::accept(bool errorOnFail) {
|
|||||||
if(isIPAddressBlocked((client_host[0] != '\0' ? client_host : "")) == true) {
|
if(isIPAddressBlocked((client_host[0] != '\0' ? client_host : "")) == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] BLOCKING connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] BLOCKING connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host);
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
::close(newSock);
|
::close(newSock);
|
||||||
newSock = INVALID_SOCKET;
|
newSock = INVALID_SOCKET;
|
||||||
#else
|
#else
|
||||||
::closesocket(newSock);
|
::closesocket(newSock);
|
||||||
newSock = -1;
|
newSock = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
Socket *result = new Socket(newSock);
|
Socket *result = new Socket(newSock);
|
||||||
result->setIpAddress((client_host[0] != '\0' ? client_host : ""));
|
result->setIpAddress((client_host[0] != '\0' ? client_host : ""));
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user