mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 21:33:59 +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());
|
||||
}
|
||||
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());
|
||||
|
||||
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());
|
||||
}
|
||||
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());
|
||||
|
||||
@@ -1545,7 +1551,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError
|
||||
int iErr = lastSocketError;
|
||||
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;
|
||||
socklen_t clilen = sizeof(cli_addr);
|
||||
char client_host[100]="";
|
||||
client_host[0]='\0';
|
||||
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();
|
||||
|
||||
if(isSocketValid(&newSock) == false) {
|
||||
@@ -2264,8 +2274,13 @@ Socket *ServerSocket::accept(bool errorOnFail) {
|
||||
|
||||
int lastSocketError = getLastSocketError();
|
||||
if(lastSocketError == PLATFORM_SOCKET_TRY_AGAIN) {
|
||||
if(attempt+1 >= max_attempts) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
sleep(0);
|
||||
}
|
||||
}
|
||||
if(errorOnFail == true) {
|
||||
throwException(szBuf);
|
||||
}
|
||||
@@ -2294,6 +2309,8 @@ Socket *ServerSocket::accept(bool errorOnFail) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
Socket *result = new Socket(newSock);
|
||||
result->setIpAddress((client_host[0] != '\0' ? client_host : ""));
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user