mirror of
https://github.com/modelec/TCPSocketClient.git
synced 2026-01-18 16:37:35 +01:00
better closing
This commit is contained in:
@@ -15,6 +15,8 @@ private:
|
||||
protected:
|
||||
bool running;
|
||||
|
||||
bool _stoped;
|
||||
|
||||
public:
|
||||
explicit TCPClient(const char* serverIP = "127.0.0.1", int port = 8080);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user