- attempt to tighten up socket connection logic that detects disconnect

This commit is contained in:
Mark Vejvoda 2011-03-26 02:00:41 +00:00
parent a3c290240c
commit 15e00694bf

View File

@ -1404,6 +1404,7 @@ bool Socket::isReadable() {
{ {
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
if(this->inSocketDestructor == true) { if(this->inSocketDestructor == true) {
SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return false; return false;
} }
safeMutexSocketDestructorFlag.ReleaseLock(); safeMutexSocketDestructorFlag.ReleaseLock();
@ -1414,7 +1415,13 @@ bool Socket::isReadable() {
if(i < 0) { if(i < 0) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,i,getLastSocketErrorFormattedText().c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,i,getLastSocketErrorFormattedText().c_str());
} }
return (i == 1);
bool result = (i == 1);
//if(result == false) {
// SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d] i = %d sock = %d\n",__FILE__,__FUNCTION__,__LINE__,i,sock);
//}
return result;
} }
bool Socket::isWritable() { bool Socket::isWritable() {
@ -1433,6 +1440,7 @@ bool Socket::isWritable() {
{ {
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
if(this->inSocketDestructor == true) { if(this->inSocketDestructor == true) {
SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return false; return false;
} }
safeMutexSocketDestructorFlag.ReleaseLock(); safeMutexSocketDestructorFlag.ReleaseLock();
@ -1443,9 +1451,13 @@ bool Socket::isWritable() {
bool result = false; bool result = false;
if(i < 0 ) { if(i < 0 ) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d] error while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
} }
else if(i == 0) { else if(i == 0) {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] TIMEOUT while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] TIMEOUT while selecting socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,i,getLastSocketErrorFormattedText().c_str());
// Assume we are still connected, write buffer could be very busy
result = true;
SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET WRITE TIMEOUT In [%s::%s Line: %d] i = %d sock = %d\n",__FILE__,__FUNCTION__,__LINE__,i,sock);
} }
else { else {
result = true; result = true;
@ -1469,6 +1481,7 @@ bool Socket::isConnected() {
int err = peek(&tmp, 1, false); int err = peek(&tmp, 1, false);
if(err <= 0 && err != PLATFORM_SOCKET_TRY_AGAIN) { if(err <= 0 && err != PLATFORM_SOCKET_TRY_AGAIN) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR Peek failed, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR Peek failed, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str());
SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET DISCONNECTED In [%s::%s Line: %d] ERROR Peek failed, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText().c_str());
return false; return false;
} }
} }