From 7850913bae21726b35331b9a2cd7626de720853b Mon Sep 17 00:00:00 2001 From: ackimixs Date: Wed, 15 May 2024 22:36:18 +0200 Subject: [PATCH] better closing --- include/TCPSocket/TCPClient.hpp | 2 ++ src/TCPClient.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/TCPSocket/TCPClient.hpp b/include/TCPSocket/TCPClient.hpp index b002bfd..c49f862 100644 --- a/include/TCPSocket/TCPClient.hpp +++ b/include/TCPSocket/TCPClient.hpp @@ -15,6 +15,8 @@ private: protected: bool running; + bool _stoped; + public: explicit TCPClient(const char* serverIP = "127.0.0.1", int port = 8080); diff --git a/src/TCPClient.cpp b/src/TCPClient.cpp index c83a18a..a33131e 100644 --- a/src/TCPClient.cpp +++ b/src/TCPClient.cpp @@ -2,7 +2,7 @@ #include "TCPSocket/TCPUtils.hpp" -TCPClient::TCPClient(const char* serverIP, int port) : running(false) { +TCPClient::TCPClient(const char* serverIP, int port) : running(false), _stoped(false) { clientSocket = socket(AF_INET, SOCK_STREAM, 0); if (clientSocket == -1) { std::cerr << "Socket creation failed" << std::endl; @@ -77,9 +77,10 @@ void TCPClient::start() { } void TCPClient::stop() { - if (running) { + if (!_stoped) { running = false; close(clientSocket); + _stoped = true; } }