MCPcopy Create free account
hub / github.com/COVESA/vsomeip / set_socket_options

Method set_socket_options

implementation/endpoints/src/local_socket_tcp_impl.cpp:194–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194void local_socket_tcp_impl::set_socket_options(configuration const& _configuration) {
195 boost::system::error_code ec;
196 // force always TCP RST on close/shutdown, in order to:
197 // 1) avoid issues with TIME_WAIT, which otherwise lasts for 120 secs with a
198 // non-responding endpoint (see also 4396812d2)
199 // 2) handle by default what needs to happen at suspend/shutdown
200 socket_->set_option(boost::asio::socket_base::linger(true, 0), ec);
201 if (ec) {
202 VSOMEIP_WARNING_P << "Could not setsockopt(SO_LINGER), " << ec.message() << ", " << name_;
203 }
204 socket_->set_option(boost::asio::socket_base::reuse_address(true), ec);
205 if (ec) {
206 VSOMEIP_WARNING_P << "Could not setsockopt(SO_REUSEADDR), " << ec.message() << ", " << name_;
207 }
208 // Nagle algorithm off
209 socket_->set_option(boost::asio::ip::tcp::no_delay(true), ec);
210 if (ec) {
211 VSOMEIP_WARNING_P << "Could not setsockopt(SO_TCP_NODELAY), " << ec.message() << ", " << name_;
212 }
213
214 // connection in the same host (and not across a host and guest or similar)
215 // important, as we can (MUST!) be lax in the socket options - no keep alive necessary
216 if (own_endpoint_.address() == peer_endpoint_.address()) {
217 // disable keep alive
218 socket_->set_option(boost::asio::socket_base::keep_alive(false), ec);
219 if (ec) {
220 VSOMEIP_WARNING_P << "Could not setsockopt(SO_KEEPALIVE) to false, " << ec.message() << ", " << name_;
221 }
222 } else {
223 // enable keep alive
224 socket_->set_option(boost::asio::socket_base::keep_alive(true), ec);
225 if (ec) {
226 VSOMEIP_WARNING_P << "Could not setsockopt(SO_KEEPALIVE) to true, " << ec.message() << ", " << name_;
227 }
228
229#if defined(__linux__) || defined(ANDROID)
230 // set a user timeout
231 // along the keep alives, this ensures connection closes if endpoint is unreachable
232 if (!socket_->set_user_timeout(_configuration.get_local_tcp_user_timeout())) {
233 VSOMEIP_WARNING_P << "Could not setsockopt(TCP_USER_TIMEOUT), errno " << errno << ", " << name_;
234 }
235
236 // override kernel settings
237 // unfortunate, but there are plenty of custom keep-alive settings, and need to
238 // enforce some sanity here
239 if (!socket_->set_keepidle(_configuration.get_local_tcp_keepidle())) {
240 VSOMEIP_WARNING_P << "Could not setsockopt(TCP_KEEPIDLE), errno " << errno << ", " << name_;
241 }
242 if (!socket_->set_keepintvl(_configuration.get_local_tcp_keepintvl())) {
243 VSOMEIP_WARNING_P << "Could not setsockopt(TCP_KEEPINTVL), errno " << errno << ", " << name_;
244 }
245 if (!socket_->set_keepcnt(_configuration.get_local_tcp_keepcnt())) {
246 VSOMEIP_WARNING_P << "Could not setsockopt(TCP_KEEPCNT), errno " << errno << ", " << name_;
247 }
248#endif
249 }
250}
251} // namespace vsomeip_v3

Callers 1

accept_cbkMethod · 0.80

Calls 10

messageMethod · 0.80
get_local_tcp_keepcntMethod · 0.80
set_optionMethod · 0.45
set_user_timeoutMethod · 0.45
set_keepidleMethod · 0.45
set_keepintvlMethod · 0.45
set_keepcntMethod · 0.45

Tested by

no test coverage detected