From b1052b879bf72ab2f5930c5f6ff0fded4a209699 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 28 Mar 2020 16:45:05 +0000 Subject: [PATCH] Rename TCP class to TCPOld --- objects.mk | 2 +- tcp.cc => tcpold.cc | 42 +++++++++++++++++++++--------------------- tcp.h => tcpold.h | 10 +++++----- vdr.cc | 42 +++++++++++++++++++++--------------------- vdr.h | 4 ++-- vdrresponsepacket.cc | 3 +-- 6 files changed, 51 insertions(+), 52 deletions(-) rename tcp.cc => tcpold.cc (92%) rename tcp.h => tcpold.h (95%) diff --git a/objects.mk b/objects.mk index a7b6201..35be1e2 100644 --- a/objects.mk +++ b/objects.mk @@ -1,4 +1,4 @@ -OBJ_COMMON = command.o thread.o timers.o i18n.o tcp.o udp4.o udp6.o vdpc.o \ +OBJ_COMMON = command.o thread.o timers.o i18n.o tcpold.o udp4.o udp6.o vdpc.o \ message.o messagequeue.o wol.o audio.o video.o log.o \ vdr.o recman.o recording.o recinfo.o channel.o rectimer.o event.o \ directory.o mark.o option.o vfeed.o afeed.o \ diff --git a/tcp.cc b/tcpold.cc similarity index 92% rename from tcp.cc rename to tcpold.cc index 40f1f95..26f6b54 100644 --- a/tcp.cc +++ b/tcpold.cc @@ -30,30 +30,30 @@ #include "log.h" -#include "tcp.h" +#include "tcpold.h" -TCP::TCP() +TCPOld::TCPOld() { sock = 0; connected = 0; timeoutEnabled = 1; } -TCP::~TCP() +TCPOld::~TCPOld() { if (connected) { CLOSESOCKET(sock); - Log::getInstance()->log("TCP", Log::DEBUG, "Have closed"); + Log::getInstance()->log("TCPOld", Log::DEBUG, "Have closed"); } } -void TCP::disableTimeout() +void TCPOld::disableTimeout() { timeoutEnabled = 0; } -void TCP::getMAC(UCHAR* dest) +void TCPOld::getMAC(UCHAR* dest) { #ifndef WIN32 struct ifreq ifr; @@ -95,7 +95,7 @@ void TCP::getMAC(UCHAR* dest) #endif } -int TCP::connectTo(char* host, unsigned short port) +int TCPOld::connectTo(char* host, unsigned short port) { #ifdef VOMP_PLATFORM_RASPBERRY #define IPV 6 @@ -247,7 +247,7 @@ The full documentation: */ } -void TCP::setReceiveWindow(size_t rxBufferSize) +void TCPOld::setReceiveWindow(size_t rxBufferSize) { // Set receive window // According to docs, optval in setsockopt is a pointer to int unless otherwise noted @@ -257,20 +257,20 @@ void TCP::setReceiveWindow(size_t rxBufferSize) #else int r = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, reinterpret_cast(&rxSize), sizeof(size_t)); #endif - Log::getInstance()->log("TCP", Log::DEBUG, "Set receive window to %i, success(=0): %i", rxBufferSize, r); + Log::getInstance()->log("TCPOld", Log::DEBUG, "Set receive window to %i, success(=0): %i", rxBufferSize, r); } -void TCP::assignSocket(int tsocket) +void TCPOld::assignSocket(int tsocket) { sock = tsocket; } -int TCP::isConnected() +int TCPOld::isConnected() { return connected; } -int TCP::sendData(void* bufR, size_t count) +int TCPOld::sendData(void* bufR, size_t count) { size_t bytes_sent = 0; int this_write; @@ -285,7 +285,7 @@ int TCP::sendData(void* bufR, size_t count) { #ifndef WIN32 this_write = write(sock, buf, count - bytes_sent); -// Log::getInstance()->log("TCP", Log::DEBUG, "TCP has written %i bytes", this_write); +// Log::getInstance()->log("TCPOld", Log::DEBUG, "TCPOld has written %i bytes", this_write); } while ( (this_write < 0) && (errno == EINTR) ); #else this_write = send(sock,(char*) buf, count- bytes_sent,0); @@ -305,7 +305,7 @@ int TCP::sendData(void* bufR, size_t count) return(count); } -int TCP::readData(void* targetBuffer, int totalBytes) +int TCPOld::readData(void* targetBuffer, int totalBytes) { UCHAR* buffer = reinterpret_cast(targetBuffer); int bytesRead = 0; @@ -325,9 +325,9 @@ int TCP::readData(void* targetBuffer, int totalBytes) FD_SET(sock, &readSet); timeout.tv_sec = 2; timeout.tv_usec = 0; - // Log::getInstance()->log("TCP", Log::DEBUG, "Going to select"); + // Log::getInstance()->log("TCPOld", Log::DEBUG, "Going to select"); success = select(sock + 1, &readSet, NULL, NULL, passToSelect); - // Log::getInstance()->log("TCP", Log::DEBUG, "Back from select with success = %i", success); + // Log::getInstance()->log("TCPOld", Log::DEBUG, "Back from select with success = %i", success); if (success < 1) { return 0; // error, or timeout @@ -337,13 +337,13 @@ int TCP::readData(void* targetBuffer, int totalBytes) #else thisRead = recv(sock, (char*)&buffer[bytesRead], totalBytes - bytesRead, 0); #endif - //Log::getInstance()->log("TCP", Log::DEBUG, "Read %i", thisRead); + //Log::getInstance()->log("TCPOld", Log::DEBUG, "Read %i", thisRead); if (!thisRead) { // if read returns 0 then connection is closed // in non-blocking mode if read is called with no data available, it returns -1 // and sets errno to EGAGAIN. but we use select so it wouldn't do that anyway. - Log::getInstance()->log("TCP", Log::ERR, "Detected connection closed"); + Log::getInstance()->log("TCPOld", Log::ERR, "Detected connection closed"); CLOSESOCKET(sock); connected = 0; return 0; @@ -357,14 +357,14 @@ int TCP::readData(void* targetBuffer, int totalBytes) { if (++readTries == 1000) { - Log::getInstance()->log("TCP", Log::ERR, "Too many reads"); + Log::getInstance()->log("TCPOld", Log::ERR, "Too many reads"); return 0; } } } } -void TCP::dump(unsigned char* data, ULONG size) +void TCPOld::dump(unsigned char* data, ULONG size) { printf("Size = %lu\n", size); @@ -493,7 +493,7 @@ void TCP::dump(unsigned char* data, ULONG size) } } -UCHAR TCP::dcc(UCHAR c) +UCHAR TCPOld::dcc(UCHAR c) { if (isspace(c)) return ' '; if (isprint(c)) return c; diff --git a/tcp.h b/tcpold.h similarity index 95% rename from tcp.h rename to tcpold.h index ceacc3c..8ec34ea 100644 --- a/tcp.h +++ b/tcpold.h @@ -19,8 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef TCP_H -#define TCP_H +#ifndef TCPOLD_H +#define TCPOLD_H #include #include @@ -46,11 +46,11 @@ #include "defines.h" -class TCP +class TCPOld { public: - TCP(); - ~TCP(); + TCPOld(); + ~TCPOld(); int connectTo(char *host, unsigned short port); void assignSocket(int tsocket); diff --git a/vdr.cc b/vdr.cc index 958ef6f..d091482 100644 --- a/vdr.cc +++ b/vdr.cc @@ -20,7 +20,7 @@ #include "vdr.h" #include "recman.h" -#include "tcp.h" +#include "tcpold.h" #include "log.h" #include "recinfo.h" #include "channel.h" @@ -166,9 +166,9 @@ int VDR::connect() maxChannelNumber = 0; channelNumberWidth = 1; - if (tcp) delete tcp; - tcp = new TCP(); - if (tcp->connectTo(serverIP, serverPort)) + if (tcpold) delete tcpold; + tcpold = new TCPOld(); + if (tcpold->connectTo(serverIP, serverPort)) { connected = true; threadStart(); @@ -183,15 +183,15 @@ int VDR::connect() void VDR::disconnect() { threadCancel(); - if (tcp) delete tcp; - tcp = NULL; + if (tcpold) delete tcpold; + tcpold = NULL; connected = false; logger->log("VDR", Log::DEBUG, "Disconnect"); } void VDR::setReceiveWindow(size_t size) { - if (connected && size) tcp->setReceiveWindow(size); + if (connected && size) tcpold->setReceiveWindow(size); } /////////////////////////////////////////////////////// @@ -222,12 +222,12 @@ void VDR::threadMethod() { timeNow = time(NULL); - readSuccess = tcp->readData(&channelID, sizeof(ULONG)); // 2s timeout atm + readSuccess = tcpold->readData(&channelID, sizeof(ULONG)); // 2s timeout atm if (!readSuccess) { //logger->log("VDR", Log::DEBUG, "Net read timeout"); - if (!tcp->isConnected()) { connectionDied(); return; } // return to stop this thread + if (!tcpold->isConnected()) { connectionDied(); return; } // return to stop this thread } // Error or timeout. @@ -264,9 +264,9 @@ void VDR::threadMethod() if (channelID == CHANNEL_REQUEST_RESPONSE) { - if (!tcp->readData(&requestID, sizeof(ULONG))) break; + if (!tcpold->readData(&requestID, sizeof(ULONG))) break; requestID = ntohl(requestID); - if (!tcp->readData(&userDataLength, sizeof(ULONG))) break; + if (!tcpold->readData(&userDataLength, sizeof(ULONG))) break; userDataLength = ntohl(userDataLength); if (userDataLength > 5000000) break; // how big can these packets get? userData = NULL; @@ -274,7 +274,7 @@ void VDR::threadMethod() { userData = malloc(userDataLength); if (!userData) break; - if (!tcp->readData(userData, userDataLength)) break; + if (!tcpold->readData(userData, userDataLength)) break; } vresp = new VDR_ResponsePacket(); @@ -290,20 +290,20 @@ void VDR::threadMethod() } else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA) { - if (!tcp->readData(&streamID, sizeof(ULONG))) break; + if (!tcpold->readData(&streamID, sizeof(ULONG))) break; streamID = ntohl(streamID); - if (!tcp->readData(&flag, sizeof(ULONG))) break; + if (!tcpold->readData(&flag, sizeof(ULONG))) break; flag = ntohl(flag); - if (!tcp->readData(&userDataLength, sizeof(ULONG))) break; + if (!tcpold->readData(&userDataLength, sizeof(ULONG))) break; userDataLength = ntohl(userDataLength); userData = NULL; if (userDataLength > 0) { userData = malloc(userDataLength); if (!userData) break; - if (!tcp->readData(userData, userDataLength)) break; + if (!tcpold->readData(userData, userDataLength)) break; } vresp = new VDR_ResponsePacket(); @@ -320,7 +320,7 @@ void VDR::threadMethod() else if (channelID == CHANNEL_KEEPALIVE) { ULONG KAreply = 0; - if (!tcp->readData(&KAreply, sizeof(ULONG))) break; + if (!tcpold->readData(&KAreply, sizeof(ULONG))) break; KAreply = ntohl(KAreply); if (KAreply == lastKAsent) // successful KA response { @@ -460,7 +460,7 @@ VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp) edMutex.lock(); - if (static_cast(tcp->sendData(vrp->getPtr(), vrp->getLen())) != vrp->getLen()) + if (static_cast(tcpold->sendData(vrp->getPtr(), vrp->getLen())) != vrp->getLen()) { edMutex.unlock(); edUnregister(&vdrpr); @@ -495,7 +495,7 @@ bool VDR::sendKA(ULONG timeStamp) buffer[pos++]=(ul>>16)&0xff; buffer[pos++]=(ul>>8)&0xff; buffer[pos++]=ul &0xff; - if (static_cast(tcp->sendData(buffer, 8)) != 8) return false; + if (static_cast(tcpold->sendData(buffer, 8)) != 8) return false; return true; } @@ -558,7 +558,7 @@ int VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigne if (!vrp.init(VDR_LOGIN, true, 6)) return 0; UCHAR mactemp[6]; - tcp->getMAC(mactemp); + tcpold->getMAC(mactemp); if (!vrp.copyin(mactemp, 6)) return 0; VDR_ResponsePacket* vresp = RequestResponse(&vrp); @@ -661,7 +661,7 @@ bool VDR::LogExtern(const char* logString) strcpy(&buffer[8], logString); - if (tcp->sendData(buffer, packetLength) != packetLength) + if (tcpold->sendData(buffer, packetLength) != packetLength) { connected = false; // stop the rest of the connection delete [] buffer; diff --git a/vdr.h b/vdr.h index 6e4dd30..af2e254 100644 --- a/vdr.h +++ b/vdr.h @@ -43,7 +43,7 @@ #include "log.h" #include "command.h" -class TCP; +class TCPOld; class Log; class RecInfo; class Event; @@ -233,7 +233,7 @@ public ExternLogger Log* logger; int initted{}; int findingServer{}; - TCP* tcp{}; + TCPOld* tcpold{}; char serverIP[40]; USHORT serverPort; bool connected{}; diff --git a/vdrresponsepacket.cc b/vdrresponsepacket.cc index 41ff522..26e2302 100644 --- a/vdrresponsepacket.cc +++ b/vdrresponsepacket.cc @@ -21,7 +21,6 @@ #include "vdrresponsepacket.h" #include "vdr.h" -#include "tcp.h" VDR_ResponsePacket::VDR_ResponsePacket() { @@ -69,7 +68,7 @@ bool VDR_ResponsePacket::end() void VDR_ResponsePacket::dumpUD() { - TCP::dump(userData, userDataLength); + // FIXME TODO - use generic stdout hex printer for userData, userDataLength } int VDR_ResponsePacket::serverError() -- 2.39.2