From 75478a9a39c236d327351ba9f55f0863395d455d Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Tue, 18 Feb 2020 21:01:30 +0100 Subject: [PATCH] Make TCPClientSocket field private Also, it is a pointer, therefore prevent bugs by disallowing copying and assignment. --- src/hardware/serialport/misc_util.cpp | 6 ------ src/hardware/serialport/misc_util.h | 9 ++++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hardware/serialport/misc_util.cpp b/src/hardware/serialport/misc_util.cpp index 99e34f36..c6b14c0e 100644 --- a/src/hardware/serialport/misc_util.cpp +++ b/src/hardware/serialport/misc_util.cpp @@ -93,9 +93,6 @@ TCPClientSocket::TCPClientSocket(int platformsocket) TCPClientSocket::TCPClientSocket(TCPsocket source) { -#ifdef NATIVESOCKETS - nativetcpstruct=0; -#endif if (!SDLNetInited) { if (SDLNet_Init() == -1) { LOG_MSG("SDLNet_Init failed: %s\n", SDLNet_GetError()); @@ -116,9 +113,6 @@ TCPClientSocket::TCPClientSocket(TCPsocket source) TCPClientSocket::TCPClientSocket(const char* destination, Bit16u port) { -#ifdef NATIVESOCKETS - nativetcpstruct=0; -#endif if (!SDLNetInited) { if (SDLNet_Init() == -1) { LOG_MSG("SDLNet_Init failed: %s\n", SDLNet_GetError()); diff --git a/src/hardware/serialport/misc_util.h b/src/hardware/serialport/misc_util.h index 8a90ba7d..c420fee3 100644 --- a/src/hardware/serialport/misc_util.h +++ b/src/hardware/serialport/misc_util.h @@ -62,9 +62,11 @@ public: TCPClientSocket(TCPsocket source); TCPClientSocket(const char* destination, Bit16u port); #ifdef NATIVESOCKETS - Bit8u* nativetcpstruct; TCPClientSocket(int platformsocket); #endif + TCPClientSocket(const TCPClientSocket&) = delete; // prevent copying + TCPClientSocket& operator=(const TCPClientSocket&) = delete; // prevent assignment + ~TCPClientSocket(); // return: @@ -88,6 +90,11 @@ public: bool SendByteBuffered(Bit8u data); private: + +#ifdef NATIVESOCKETS + Bit8u *nativetcpstruct = nullptr; +#endif + TCPsocket mysock = 0; SDLNet_SocketSet listensocketset = nullptr;