diff options
Diffstat (limited to 'implementation/endpoints')
4 files changed, 48 insertions, 46 deletions
diff --git a/implementation/endpoints/src/endpoint_manager_impl.cpp b/implementation/endpoints/src/endpoint_manager_impl.cpp index 32ba31d..38dabf7 100644 --- a/implementation/endpoints/src/endpoint_manager_impl.cpp +++ b/implementation/endpoints/src/endpoint_manager_impl.cpp @@ -266,7 +266,9 @@ std::shared_ptr<endpoint> endpoint_manager_impl::create_server_endpoint( << " Server endpoint creation failed." << " Reason: "<< e.what() << " Port: " << _port - << " (" << _reliable << ")"; + << " (reliable=" + << (_reliable ? "reliable" : "unreliable") + << ")"; } return (its_endpoint); diff --git a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp index c490f53..3debcc7 100644 --- a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp @@ -175,26 +175,24 @@ void tcp_client_endpoint_impl::connect() { } #endif - // In case a client endpoint port was configured, - // bind to it before connecting - if (local_.port() != ILLEGAL_PORT) { - boost::system::error_code its_bind_error; - socket_->bind(local_, its_bind_error); - if(its_bind_error) { - VSOMEIP_WARNING << "tcp_client_endpoint::connect: " - "Error binding socket: " << its_bind_error.message() - << " remote:" << get_address_port_remote(); - try { - // don't connect on bind error to avoid using a random port - strand_.post(std::bind(&client_endpoint_impl::connect_cbk, - shared_from_this(), its_bind_error)); - } catch (const std::exception &e) { - VSOMEIP_ERROR << "tcp_client_endpoint_impl::connect: " - << e.what() << " remote:" << get_address_port_remote(); - } - return; + // Bind address and, optionally, port. + boost::system::error_code its_bind_error; + socket_->bind(local_, its_bind_error); + if(its_bind_error) { + VSOMEIP_WARNING << "tcp_client_endpoint::connect: " + "Error binding socket: " << its_bind_error.message() + << " remote:" << get_address_port_remote(); + try { + // don't connect on bind error to avoid using a random port + strand_.post(std::bind(&client_endpoint_impl::connect_cbk, + shared_from_this(), its_bind_error)); + } catch (const std::exception &e) { + VSOMEIP_ERROR << "tcp_client_endpoint_impl::connect: " + << e.what() << " remote:" << get_address_port_remote(); } + return; } + state_ = cei_state_e::CONNECTING; connect_timepoint_ = std::chrono::steady_clock::now(); aborted_restart_count_ = 0; diff --git a/implementation/endpoints/src/udp_client_endpoint_impl.cpp b/implementation/endpoints/src/udp_client_endpoint_impl.cpp index ff24173..dc7a7bf 100644 --- a/implementation/endpoints/src/udp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_client_endpoint_impl.cpp @@ -84,11 +84,6 @@ void udp_client_endpoint_impl::connect() { } } - if (local_.port() == ILLEGAL_PORT) { - // Let the OS assign the port - local_.port(0); - } - #ifndef _WIN32 // If specified, bind to device std::string its_device(configuration_->get_device()); @@ -100,25 +95,22 @@ void udp_client_endpoint_impl::connect() { } #endif - // In case a client endpoint port was configured, - // bind to it before connecting - if (local_.port() != ILLEGAL_PORT) { - boost::system::error_code its_bind_error; - socket_->bind(local_, its_bind_error); - if(its_bind_error) { - VSOMEIP_WARNING << "udp_client_endpoint::connect: " - "Error binding socket: " << its_bind_error.message() - << " remote:" << get_address_port_remote(); - try { - // don't connect on bind error to avoid using a random port - strand_.post(std::bind(&client_endpoint_impl::connect_cbk, - shared_from_this(), its_bind_error)); - } catch (const std::exception &e) { - VSOMEIP_ERROR << "udp_client_endpoint_impl::connect: " - << e.what() << " remote:" << get_address_port_remote(); - } - return; + // Bind address and, optionally, port. + boost::system::error_code its_bind_error; + socket_->bind(local_, its_bind_error); + if(its_bind_error) { + VSOMEIP_WARNING << "udp_client_endpoint::connect: " + "Error binding socket: " << its_bind_error.message() + << " remote:" << get_address_port_remote(); + try { + // don't connect on bind error to avoid using a random port + strand_.post(std::bind(&client_endpoint_impl::connect_cbk, + shared_from_this(), its_bind_error)); + } catch (const std::exception &e) { + VSOMEIP_ERROR << "udp_client_endpoint_impl::connect: " + << e.what() << " remote:" << get_address_port_remote(); } + return; } state_ = cei_state_e::CONNECTING; diff --git a/implementation/endpoints/src/udp_server_endpoint_impl.cpp b/implementation/endpoints/src/udp_server_endpoint_impl.cpp index add828c..bd6fc62 100644 --- a/implementation/endpoints/src/udp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_server_endpoint_impl.cpp @@ -369,12 +369,22 @@ void udp_server_endpoint_impl::join_unlocked(const std::string &_address) { #ifdef _WIN32 const char* optval("0001"); - ::setsockopt(multicast_socket_->native_handle(), IPPROTO_IP, IP_PKTINFO, - optval, sizeof(optval)); + if (is_v4) { + ::setsockopt(multicast_socket_->native_handle(), IPPROTO_IP, IP_PKTINFO, + optval, sizeof(optval)); + } else if (is_v6) { + ::setsockopt(multicast_socket_->native_handle(), IPPROTO_IPV6, IPV6_PKTINFO, + optval, sizeof(optval)); + } #else int optval(1); - ::setsockopt(multicast_socket_->native_handle(), IPPROTO_IP, IP_PKTINFO, - &optval, sizeof(optval)); + if (is_v4) { + ::setsockopt(multicast_socket_->native_handle(), IPPROTO_IP, IP_PKTINFO, + &optval, sizeof(optval)); + } else { + ::setsockopt(multicast_socket_->native_handle(), IPPROTO_IPV6, IPV6_RECVPKTINFO, + &optval, sizeof(optval)); + } #endif multicast_id_++; receive_multicast(multicast_id_); |