Commit bd5935ce authored by Dominik Charousset's avatar Dominik Charousset

Fix `new_tcp_connection_impl` for IPv6

parent 3385553b
...@@ -186,10 +186,10 @@ behavior basp_broker::make_behavior() { ...@@ -186,10 +186,10 @@ behavior basp_broker::make_behavior() {
try { try {
assign_tcp_scribe(hdl); assign_tcp_scribe(hdl);
} }
catch (...) { catch (std::exception& e) {
CAF_LOG_DEBUG("failed to assign scribe from handle"); CAF_LOG_DEBUG("failed to assign scribe from handle: " << e.what());
send(client, error_atom::value, request_id, send(client, error_atom::value, request_id,
"failed to assign scribe from handle"); std::string("failed to assign scribe from handle: ") + e.what());
return; return;
} }
auto& ctx = m_ctx[hdl]; auto& ctx = m_ctx[hdl];
......
...@@ -113,6 +113,7 @@ namespace network { ...@@ -113,6 +113,7 @@ namespace network {
} }
void nonblocking(native_socket fd, bool new_value) { void nonblocking(native_socket fd, bool new_value) {
CAF_LOGF_TRACE(CAF_ARG(fd) << ", " << CAF_ARG(new_value));
// read flags for fd // read flags for fd
auto rf = ccall(cc_not_minus1, "cannot read flags", fcntl, fd, F_GETFL, 0); auto rf = ccall(cc_not_minus1, "cannot read flags", fcntl, fd, F_GETFL, 0);
// calculate and set new flags // calculate and set new flags
...@@ -864,6 +865,7 @@ default_multiplexer::add_tcp_doorman(broker* self, uint16_t port, ...@@ -864,6 +865,7 @@ default_multiplexer::add_tcp_doorman(broker* self, uint16_t port,
******************************************************************************/ ******************************************************************************/
void tcp_nodelay(native_socket fd, bool new_value) { void tcp_nodelay(native_socket fd, bool new_value) {
CAF_LOGF_TRACE(CAF_ARG(fd) << ", " << CAF_ARG(new_value));
int flag = new_value ? 1 : 0; int flag = new_value ? 1 : 0;
ccall(cc_zero, "unable to set TCP_NODELAY", setsockopt, fd, IPPROTO_TCP, ccall(cc_zero, "unable to set TCP_NODELAY", setsockopt, fd, IPPROTO_TCP,
TCP_NODELAY, reinterpret_cast<setsockopt_ptr>(&flag), TCP_NODELAY, reinterpret_cast<setsockopt_ptr>(&flag),
...@@ -965,7 +967,7 @@ default_socket::~default_socket() { ...@@ -965,7 +967,7 @@ default_socket::~default_socket() {
void default_socket::close_read() { void default_socket::close_read() {
if (m_fd != invalid_native_socket) { if (m_fd != invalid_native_socket) {
::shutdown(m_fd, 0); // 0 identifyies the read channel on Win & UNIX ::shutdown(m_fd, 0); // 0 identifies the read channel on Win & UNIX
} }
} }
...@@ -976,8 +978,7 @@ class socket_guard { ...@@ -976,8 +978,7 @@ class socket_guard {
} }
~socket_guard() { ~socket_guard() {
if (m_fd != invalid_native_socket) close();
closesocket(m_fd);
} }
native_socket release() { native_socket release() {
...@@ -986,6 +987,13 @@ class socket_guard { ...@@ -986,6 +987,13 @@ class socket_guard {
return fd; return fd;
} }
void close() {
if (m_fd != invalid_native_socket) {
closesocket(m_fd);
m_fd = invalid_native_socket;
}
}
private: private:
native_socket m_fd; native_socket m_fd;
}; };
...@@ -1066,9 +1074,10 @@ native_socket new_tcp_connection_impl(const std::string& host, uint16_t port, ...@@ -1066,9 +1074,10 @@ native_socket new_tcp_connection_impl(const std::string& host, uint16_t port,
socket_guard sguard(fd); socket_guard sguard(fd);
if (proto == ipv6) { if (proto == ipv6) {
if (ip_connect<AF_INET6>(fd, res->first, port)) { if (ip_connect<AF_INET6>(fd, res->first, port)) {
CAF_LOGF_INFO("successfully connected to host"); CAF_LOGF_INFO("successfully connected to host via IPv6");
return fd; return sguard.release();
} }
sguard.close();
// IPv4 fallback // IPv4 fallback
return new_tcp_connection_impl(host, port, ipv4); return new_tcp_connection_impl(host, port, ipv4);
} }
...@@ -1076,6 +1085,7 @@ native_socket new_tcp_connection_impl(const std::string& host, uint16_t port, ...@@ -1076,6 +1085,7 @@ native_socket new_tcp_connection_impl(const std::string& host, uint16_t port,
CAF_LOGF_ERROR("could not connect to to " << host << " on port " << port); CAF_LOGF_ERROR("could not connect to to " << host << " on port " << port);
throw network_error("could not connect to " + host); throw network_error("could not connect to " + host);
} }
CAF_LOGF_INFO("successfully connected to host via IPv4");
return sguard.release(); return sguard.release();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment