diff options
Diffstat (limited to 'louloulibs')
-rw-r--r-- | louloulibs/network/tcp_socket_handler.cpp | 8 | ||||
-rw-r--r-- | louloulibs/network/tcp_socket_handler.hpp | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 0ed74a2..d5c0dfa 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -44,8 +44,16 @@ TCPSocketHandler::TCPSocketHandler(std::shared_ptr<Poller> poller): #endif {} +TCPSocketHandler::~TCPSocketHandler() +{ + this->close(); +} + + void TCPSocketHandler::init_socket(const struct addrinfo* rp) { + if (this->socket != -1) + ::close(this->socket); if ((this->socket = ::socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) == -1) throw std::runtime_error("Could not create socket: "s + strerror(errno)); int optval = 1; diff --git a/louloulibs/network/tcp_socket_handler.hpp b/louloulibs/network/tcp_socket_handler.hpp index 213e286..d33b919 100644 --- a/louloulibs/network/tcp_socket_handler.hpp +++ b/louloulibs/network/tcp_socket_handler.hpp @@ -27,7 +27,7 @@ class TCPSocketHandler: public SocketHandler { protected: - ~TCPSocketHandler() = default; + ~TCPSocketHandler(); public: explicit TCPSocketHandler(std::shared_ptr<Poller> poller); |