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

Method connect

implementation/endpoints/src/udp_client_endpoint_impl.cpp:50–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50void udp_client_endpoint_impl::connect() {
51 std::unique_lock its_lock(socket_mutex_);
52 boost::system::error_code its_error;
53 socket_->open(remote_.protocol(), its_error);
54 if (!its_error || its_error == boost::asio::error::already_open) {
55 // Enable SO_REUSEADDR to avoid bind problems with services going offline
56 // and coming online again and the user has specified only a small number
57 // of ports in the clients section for one service instance
58 socket_->set_option(boost::asio::socket_base::reuse_address(true), its_error);
59 if (its_error) {
60 VSOMEIP_WARNING_P << "Couldn't enable SO_REUSEADDR: " << its_error.message() << " remote:" << get_address_port_remote();
61 }
62 socket_->set_option(boost::asio::socket_base::receive_buffer_size(static_cast<int>(udp_receive_buffer_size_)), its_error);
63 if (its_error) {
64 VSOMEIP_WARNING_P << "Couldn't set SO_RCVBUF: " << its_error.message() << " to: " << udp_receive_buffer_size_
65 << " local port:" << local_.port() << " remote:" << get_address_port_remote();
66 }
67
68 boost::asio::socket_base::receive_buffer_size its_option;
69 socket_->get_option(its_option, its_error);
70#ifdef __linux__
71 // If regular setting of the buffer size did not work, try to force
72 // (requires CAP_NET_ADMIN to be successful)
73 if (its_option.value() < 0 || its_option.value() < udp_receive_buffer_size_) {
74 socket_->set_option(udp_receive_buffer_force{udp_receive_buffer_size_}, its_error);
75 if (!its_error) {
76 VSOMEIP_INFO_P << "SO_RCVBUFFORCE successful!";
77 } else {
78 VSOMEIP_INFO_P << "SO_RCVBUFFORCE failed, " << its_error.message();
79 its_error = {};
80 }
81 socket_->get_option(its_option, its_error);
82 }
83#endif
84 if (its_error) {
85 VSOMEIP_WARNING_P << "Couldn't get SO_RCVBUF: " << its_error.message() << " local port:" << local_.port()
86 << " remote:" << get_address_port_remote();
87 } else {
88 VSOMEIP_INFO_P << "SO_RCVBUF is: " << its_option.value() << " (" << udp_receive_buffer_size_ << ")"
89 << " local port:" << local_.port() << " remote:" << get_address_port_remote();
90 }
91
92 if (local_.port() == ILLEGAL_PORT) {
93 // Let the OS assign the port
94 local_.port(0);
95 }
96
97#if defined(__linux__) || defined(__QNX__)
98 // If specified, bind to device
99 std::string its_device(configuration_->get_device());
100 if (its_device != "") {
101 boost::system::error_code its_ec{};
102 socket_->set_option(udp_bind_to_device{its_device}, its_ec);
103 if (its_ec) {
104 VSOMEIP_WARNING_P << "Could not bind to device \"" << its_device << "\", " << its_ec.message();
105 }
106 }
107#endif

Callers

nothing calls this directly

Calls 13

messageMethod · 0.80
unlockMethod · 0.80
lockMethod · 0.80
on_bind_errorMethod · 0.80
openMethod · 0.45
protocolMethod · 0.45
set_optionMethod · 0.45
get_optionMethod · 0.45
bindMethod · 0.45
to_stringMethod · 0.45
local_endpointMethod · 0.45
async_connectMethod · 0.45

Tested by

no test coverage detected