From 54338461dc9238e0b2c230aa4731c861d68eaabb Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 9 Nov 2013 19:30:36 +0000 Subject: [PATCH] add timer for socket write errors to avoid performance penalty when writing to console --- source/shared_lib/include/platform/posix/socket.h | 1 + source/shared_lib/sources/platform/posix/socket.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index b80a040e..8b707635 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -150,6 +150,7 @@ protected: bool inSocketDestructor; bool isSocketBlocking; + time_t lastSocketError; public: Socket(PLATFORM_SOCKET sock); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index bace6026..4438c38f 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -783,6 +783,7 @@ Socket::Socket(PLATFORM_SOCKET sock) { dataSynchAccessorRead = new Mutex(); dataSynchAccessorWrite = new Mutex(); inSocketDestructorSynchAccessor = new Mutex(); + lastSocketError = 0; MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE); inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE); @@ -805,6 +806,7 @@ Socket::Socket() { dataSynchAccessorRead = new Mutex(); dataSynchAccessorWrite = new Mutex(); inSocketDestructorSynchAccessor = new Mutex(); + lastSocketError = 0; MutexSafeWrapper safeMutexSocketDestructorFlag(inSocketDestructorSynchAccessor,CODE_AT_LINE); inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE); @@ -1747,13 +1749,17 @@ bool Socket::isWritable(struct timeval *timeVal, bool lockMutex) { bool result = false; 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()); + 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) { //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); + 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 { result = true;