diff --git a/sources/network/tcp_client.cpp b/sources/network/tcp_client.cpp index 29707e5..b53e502 100644 --- a/sources/network/tcp_client.cpp +++ b/sources/network/tcp_client.cpp @@ -61,8 +61,14 @@ void tcp_client::connect(const std::string& host, std::uint32_t port) { if (is_connected()) { __TACOPIE_THROW(warn, "tcp_client is already connected"); } - m_socket.connect(host, port); - m_io_service->track(m_socket); + try { + m_socket.connect(host, port); + m_io_service->track(m_socket); + } + catch (const tacopie_error& e) { + m_socket.close(); + throw e; + } m_is_connected = true; diff --git a/sources/network/unix/io_service.cpp b/sources/network/unix/io_service.cpp index 0799e4b..6043c44 100644 --- a/sources/network/unix/io_service.cpp +++ b/sources/network/unix/io_service.cpp @@ -233,9 +233,10 @@ io_service::track(const tcp_socket& socket, const event_callback_t& rd_callback, __TACOPIE_LOG(debug, "track new socket"); - auto& track_info = m_tracked_sockets[socket.get_fd()]; - track_info.rd_callback = rd_callback; - track_info.wr_callback = wr_callback; + auto& track_info = m_tracked_sockets[socket.get_fd()]; + track_info.rd_callback = rd_callback; + track_info.wr_callback = wr_callback; + track_info.marked_for_untrack = false; m_notifier.notify(); }