return connected;
}
+/*
UCHAR* TCP::receivePacket()
{
if (!connected) return NULL;
dataLength = packetLength;
return buffer;
}
+*/
int TCP::getDataLength()
{
{
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
}
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
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
pthread_detach(runThread); // Detach
- tcp.disableReadTimeout();
+// tcp.disableReadTimeout();
- tcp.setSoKeepTime(3);
+// tcp.setSoKeepTime(3);
tcp.setNonBlocking();
ULONG channelID;
{
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)
{