From 7b42d0c825e84dbdf0a07dcbc5babe34613375ff Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 1 Jun 2008 15:29:35 +0000 Subject: [PATCH] Server side timeouts --- tcp.c | 8 +++++--- tcp.h | 2 +- vompclient.c | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tcp.c b/tcp.c index 9fdcf56..fb1a860 100644 --- a/tcp.c +++ b/tcp.c @@ -125,6 +125,7 @@ int TCP::isConnected() return connected; } +/* UCHAR* TCP::receivePacket() { if (!connected) return NULL; @@ -157,6 +158,7 @@ UCHAR* TCP::receivePacket() dataLength = packetLength; return buffer; } +*/ int TCP::getDataLength() { @@ -182,13 +184,13 @@ int TCP::readData(UCHAR* buffer, int totalBytes) { FD_ZERO(&readSet); FD_SET(sock, &readSet); - timeout.tv_sec = 10; + timeout.tv_sec = 20; timeout.tv_usec = 0; success = select(sock + 1, &readSet, NULL, NULL, passToSelect); if (success < 1) { - cleanup(); - log->log("TCP", Log::DEBUG, "TCP: error or timeout"); +// cleanup(); + log->log("TCP", Log::DEBUG, "Select finished with %i", success); return 0; // error, or timeout } diff --git a/tcp.h b/tcp.h index 4364798..7f33645 100644 --- a/tcp.h +++ b/tcp.h @@ -59,7 +59,7 @@ class TCP int connectTo(char *host, unsigned short port); int sendPacket(UCHAR*, size_t size); - UCHAR* receivePacket(); +// UCHAR* receivePacket(); int readData(UCHAR* buffer, int totalBytes); // Get methods diff --git a/vompclient.c b/vompclient.c index 2b28b97..4a2692c 100644 --- a/vompclient.c +++ b/vompclient.c @@ -162,9 +162,9 @@ void VompClient::run2() pthread_sigmask(SIG_BLOCK, &sigset, NULL); pthread_detach(runThread); // Detach - tcp.disableReadTimeout(); +// tcp.disableReadTimeout(); - tcp.setSoKeepTime(3); +// tcp.setSoKeepTime(3); tcp.setNonBlocking(); ULONG channelID; @@ -179,7 +179,18 @@ void VompClient::run2() { log->log("Client", Log::DEBUG, "Waiting"); - if (!tcp.readData((UCHAR*)&channelID, sizeof(ULONG))) break; + if (!tcp.readData((UCHAR*)&channelID, sizeof(ULONG))) + { + // If this read fails then the client just hasn't sent anything. + // If any of the lower reads fail, then break, the connection is probably dead + + // check connection is ok +// if (tcp.isConnected()) continue; + + log->log("Client", Log::DEBUG, "Disconnection detected"); + break; + } + channelID = ntohl(channelID); if (channelID == 1) { -- 2.39.2