revert network code back to beta1 code

This commit is contained in:
Mark Vejvoda
2011-11-27 05:27:50 +00:00
parent 058548c208
commit 03a7a72ef5
12 changed files with 155 additions and 369 deletions

View File

@@ -785,25 +785,26 @@ bool Socket::isSocketValid(const PLATFORM_SOCKET *validateSocket) {
}
Socket::Socket(PLATFORM_SOCKET sock) {
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,true,CODE_AT_LINE);
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
//this->inSocketDestructor = false;
this->inSocketDestructor = false;
//safeMutexSocketDestructorFlag.ReleaseLock();
//this->pingThread = NULL;
//pingThreadAccessor.setOwnerId(CODE_AT_LINE);
//dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
//dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
dataSynchAccessorRWLMutex.setOwnerId(CODE_AT_LINE);
dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
this->sock= sock;
this->connectedIpAddress = "";
}
Socket::Socket() {
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,true,CODE_AT_LINE);
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
//this->inSocketDestructor = false;
this->inSocketDestructor = false;
//safeMutexSocketDestructorFlag.ReleaseLock();
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -905,13 +906,13 @@ void Socket::simpleTask(BaseThread *callingThread) {
*/
Socket::~Socket() {
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,false,CODE_AT_LINE);
//if(this->inSocketDestructor == true) {
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
// return;
//}
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__);
return;
}
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
//this->inSocketDestructor = true;
this->inSocketDestructor = true;
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
@@ -920,12 +921,12 @@ Socket::~Socket() {
disconnectSocket();
// Allow other callers with a lock on the mutexes to let them go
//for(time_t elapsed = time(NULL);
// (dataSynchAccessorRead.getRefCount() > 0 ||
// dataSynchAccessorWrite.getRefCount() > 0) &&
// difftime(time(NULL),elapsed) <= 5;) {
for(time_t elapsed = time(NULL);
(dataSynchAccessorRead.getRefCount() > 0 ||
dataSynchAccessorWrite.getRefCount() > 0) &&
difftime(time(NULL),elapsed) <= 5;) {
//sleep(0);
//}
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
@@ -940,9 +941,8 @@ void Socket::disconnectSocket() {
if(isSocketValid() == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling shutdown and close for socket = %d...\n",__FILE__,__FUNCTION__,sock);
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
//MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
::shutdown(sock,2);
#ifndef WIN32
::close(sock);
@@ -951,8 +951,8 @@ void Socket::disconnectSocket() {
::closesocket(sock);
sock = -1;
#endif
//safeMutex.ReleaseLock();
//safeMutex1.ReleaseLock();
safeMutex.ReleaseLock();
safeMutex1.ReleaseLock();
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
@@ -1183,8 +1183,7 @@ int Socket::send(const void *data, int dataSize) {
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
#ifdef __APPLE__
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
@@ -1222,8 +1221,7 @@ int Socket::send(const void *data, int dataSize) {
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
#ifdef __APPLE__
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
#else
@@ -1272,8 +1270,7 @@ int Socket::send(const void *data, int dataSize) {
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
const char *sendBuf = (const char *)data;
#ifdef __APPLE__
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, SO_NOSIGPIPE);
@@ -1338,8 +1335,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
safeMutex.ReleaseLock();
}
@@ -1368,8 +1364,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
safeMutex.ReleaseLock();
@@ -1428,8 +1423,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
@@ -1468,8 +1462,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
// safeMutexSocketDestructorFlag.ReleaseLock();
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
safeMutex.ReleaseLock();
@@ -1764,8 +1757,7 @@ void ClientSocket::connect(const Ip &ip, int port)
FD_SET(sock, &myset);
{
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
//safeMutex.ReleaseLock();
}
@@ -2181,8 +2173,7 @@ Socket *ServerSocket::accept() {
struct sockaddr_in cli_addr;
socklen_t clilen = sizeof(cli_addr);
char client_host[100]="";
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
safeMutex.ReleaseLock();