diff --git a/source/shared_lib/include/platform/posix/socket.h b/source/shared_lib/include/platform/posix/socket.h index 21a8e2db9..4bb530ffa 100644 --- a/source/shared_lib/include/platform/posix/socket.h +++ b/source/shared_lib/include/platform/posix/socket.h @@ -168,8 +168,8 @@ public: static void setBlock(bool block, PLATFORM_SOCKET socket); bool getBlock(); - bool isReadable(); - bool isWritable(struct timeval *timeVal=NULL); + bool isReadable(bool lockMutex=false); + bool isWritable(struct timeval *timeVal=NULL,bool lockMutex=false); bool isConnected(); static string getHostName(); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 952d6294a..ff629b6bc 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1396,7 +1396,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while receiving socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText(&iErr).c_str()); break; } - else if(Socket::isReadable() == true) { + else if(Socket::isReadable(true) == true) { // MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE); // if(this->inSocketDestructor == true) { // SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__); @@ -1544,7 +1544,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData,int *pLastSocketError break; } */ - if(Socket::isReadable() == true) { + if(Socket::isReadable(true) == true) { // MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE); // if(this->inSocketDestructor == true) { @@ -1661,7 +1661,7 @@ void Socket::setBlock(bool block, PLATFORM_SOCKET socket) { } } -bool Socket::isReadable() { +bool Socket::isReadable(bool lockMutex) { if(isSocketValid() == false) return false; struct timeval tv; @@ -1670,6 +1670,12 @@ bool Socket::isReadable() { fd_set set; FD_ZERO(&set); + + MutexSafeWrapper safeMutex(NULL,CODE_AT_LINE); + if(lockMutex == true) { + safeMutex.setMutex(dataSynchAccessorRead,CODE_AT_LINE); + } + FD_SET(sock, &set); int i = 0; @@ -1697,7 +1703,7 @@ bool Socket::isReadable() { return result; } -bool Socket::isWritable(struct timeval *timeVal) { +bool Socket::isWritable(struct timeval *timeVal, bool lockMutex) { if(isSocketValid() == false) return false; struct timeval tv; @@ -1712,6 +1718,11 @@ bool Socket::isWritable(struct timeval *timeVal) { fd_set set; FD_ZERO(&set); + + MutexSafeWrapper safeMutex(NULL,CODE_AT_LINE); + if(lockMutex == true) { + safeMutex.setMutex(dataSynchAccessorWrite,CODE_AT_LINE); + } FD_SET(sock, &set); int i = 0; @@ -1757,12 +1768,12 @@ bool Socket::isConnected() { // inSocketDestructorSynchAccessor->setOwnerId(CODE_AT_LINE); //if the socket is not writable then it is not conencted - if(isWritable() == false) { + if(isWritable(NULL,true) == false) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR isWritable failed.\n",__FILE__,__FUNCTION__,__LINE__); return false; } //if the socket is readable it is connected if we can read a byte from it - if(isReadable()) { + if(isReadable(true)) { char tmp=0; int peekDataBytes=1; int lastSocketError=0;