summaryrefslogtreecommitdiff
path: root/louloulibs/network/tcp_socket_handler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'louloulibs/network/tcp_socket_handler.cpp')
-rw-r--r--louloulibs/network/tcp_socket_handler.cpp8
1 files changed, 8 insertions, 0 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;