| 107 | } |
| 108 | |
| 109 | void tcp_client_endpoint_impl::connect() { |
| 110 | start_connecting_timer(); |
| 111 | std::unique_lock its_lock(socket_mutex_); |
| 112 | boost::system::error_code its_error; |
| 113 | socket_->open(remote_.protocol(), its_error); |
| 114 | |
| 115 | if (!its_error || its_error == boost::asio::error::already_open) { |
| 116 | // Nagle algorithm off |
| 117 | socket_->set_option(boost::asio::ip::tcp::no_delay(true), its_error); |
| 118 | if (its_error) { |
| 119 | VSOMEIP_WARNING_P << "Couldn't disable Nagle algorithm: " << its_error.message() << " remote:" << get_address_port_remote(); |
| 120 | } |
| 121 | |
| 122 | socket_->set_option(boost::asio::socket_base::keep_alive(true), its_error); |
| 123 | if (its_error) { |
| 124 | VSOMEIP_WARNING_P << "Couldn't enable keep_alive: " << its_error.message() << " remote:" << get_address_port_remote(); |
| 125 | } |
| 126 | |
| 127 | // Enable SO_REUSEADDR to avoid bind problems with services going offline |
| 128 | // and coming online again and the user has specified only a small number |
| 129 | // of ports in the clients section for one service instance |
| 130 | socket_->set_option(boost::asio::socket_base::reuse_address(true), its_error); |
| 131 | if (its_error) { |
| 132 | VSOMEIP_WARNING_P << "Couldn't enable SO_REUSEADDR: " << its_error.message() << " remote:" << get_address_port_remote(); |
| 133 | } |
| 134 | |
| 135 | // force always TCP RST on close/shutdown, in order to: |
| 136 | // 1) avoid issues with TIME_WAIT, which otherwise lasts for 120 secs with a |
| 137 | // non-responding endpoint (see also 4396812d2) |
| 138 | // 2) handle by default what needs to happen at suspend/shutdown |
| 139 | socket_->set_option(boost::asio::socket_base::linger(true, 0), its_error); |
| 140 | if (its_error) { |
| 141 | VSOMEIP_WARNING_P << "Couldn't enable SO_LINGER: " << its_error.message() << " remote:" << get_address_port_remote(); |
| 142 | } |
| 143 | |
| 144 | #if defined(__linux__) |
| 145 | // set a user timeout |
| 146 | // along the keep alives, this ensures connection closes if endpoint is unreachable |
| 147 | if (!(socket_->set_user_timeout(VSOMEIP_TCP_USER_TIMEOUT))) { |
| 148 | VSOMEIP_WARNING_P << "Could not setsockopt(TCP_USER_TIMEOUT), errno " << errno; |
| 149 | } |
| 150 | |
| 151 | // override kernel settings |
| 152 | // unfortunate, but there are plenty of custom keep-alive settings, and need to |
| 153 | // enforce some sanity here |
| 154 | if (!(socket_->set_keepidle(configuration_->get_external_tcp_keepidle()))) { |
| 155 | VSOMEIP_WARNING_P << "Could not setsockopt(TCP_KEEPIDLE), errno " << errno; |
| 156 | } |
| 157 | |
| 158 | if (!(socket_->set_keepintvl(configuration_->get_external_tcp_keepintvl()))) { |
| 159 | VSOMEIP_WARNING_P << "Could not setsockopt(TCP_KEEPINTVL), errno " << errno; |
| 160 | } |
| 161 | |
| 162 | if (!(socket_->set_keepcnt(configuration_->get_external_tcp_keepcnt()))) { |
| 163 | VSOMEIP_WARNING_P << "Could not setsockopt(TCP_KEEPCNT), errno " << errno; |
| 164 | } |
| 165 | #endif |
| 166 |
nothing calls this directly
no test coverage detected