add timer for socket write errors to avoid performance penalty when writing to console

This commit is contained in:
Mark Vejvoda
2013-11-09 19:30:36 +00:00
parent bb2e2d0f64
commit 54338461dc
2 changed files with 8 additions and 1 deletions

View File

@@ -150,6 +150,7 @@ protected:
bool inSocketDestructor; bool inSocketDestructor;
bool isSocketBlocking; bool isSocketBlocking;
time_t lastSocketError;
public: public:
Socket(PLATFORM_SOCKET sock); Socket(PLATFORM_SOCKET sock);

View File

@@ -783,6 +783,7 @@ Socket::Socket(PLATFORM_SOCKET sock) {
dataSynchAccessorRead = new Mutex(); dataSynchAccessorRead = new Mutex();
dataSynchAccessorWrite = new Mutex(); dataSynchAccessorWrite = new Mutex();
inSocketDestructorSynchAccessor = new Mutex(); inSocketDestructorSynchAccessor = new Mutex();
lastSocketError = 0;
MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE); MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE);
inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE); inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
@@ -805,6 +806,7 @@ Socket::Socket() {
dataSynchAccessorRead = new Mutex(); dataSynchAccessorRead = new Mutex();
dataSynchAccessorWrite = new Mutex(); dataSynchAccessorWrite = new Mutex();
inSocketDestructorSynchAccessor = new Mutex(); inSocketDestructorSynchAccessor = new Mutex();
lastSocketError = 0;
MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE); MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE);
inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE); inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE);
@@ -1747,13 +1749,17 @@ bool Socket::isWritable(struct timeval *timeVal, bool lockMutex) {
bool result = false; bool result = false;
if(i < 0 ) { if(i < 0 ) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) 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()); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) 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()); 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 // Assume we are still connected, write buffer could be very busy
result = true; result = true;
SystemFlags::OutputDebug(SystemFlags::debugError,"SOCKET WRITE TIMEOUT In [%s::%s Line: %d] i = %d sock = %d\n",__FILE__,__FUNCTION__,__LINE__,i,sock); if(difftime(time(NULL),lastSocketError) > 1) {
lastSocketError = time(NULL);
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;