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

Method start

implementation/endpoints/src/netlink_connector.cpp:38–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void netlink_connector::start() {
39 std::unique_lock its_lock(socket_mutex_);
40 boost::system::error_code ec;
41 if (socket_.is_open()) {
42 // It is inherently unsafe to receive multiple starts
43 // due to internal data not being protected by mutexes.
44
45 socket_.close(ec);
46 if (ec) {
47 VSOMEIP_WARNING << "Error closing NETLINK socket: " << ec.message();
48 }
49 }
50 socket_.open(nl_protocol(NETLINK_ROUTE), ec);
51 if (ec) {
52 VSOMEIP_ERROR << "Error opening NETLINK socket: " << ec.message();
53 return;
54 }
55
56 if (socket_.is_open()) {
57 int group = RTMGRP_LINK;
58
59 if (address_.is_v4()) {
60 group |= RTMGRP_IPV4_IFADDR;
61 } else if (address_.is_v6()) {
62 group |= RTMGRP_IPV6_IFADDR;
63 }
64
65 if (multicast_address_.is_v4() && !multicast_address_.is_unspecified()) {
66 group |= RTMGRP_IPV4_ROUTE;
67 } else if (multicast_address_.is_v6() && !multicast_address_.is_unspecified()) {
68 group |= RTMGRP_IPV6_ROUTE;
69 }
70
71 socket_.bind(nl_endpoint<nl_protocol>(group), ec);
72
73 if (ec && ec != boost::asio::error::address_in_use) {
74 VSOMEIP_ERROR << "Error binding NETLINK socket: " << ec.message();
75 return;
76 }
77
78 // TODO: replace socket_mutex_ by a proper locking mechanism
79 its_lock.unlock();
80 set_state(state_e::RESET);
81 socket_.async_receive(boost::asio::buffer(&recv_buffer_[0], recv_buffer_.size()),
82 std::bind(&netlink_connector::receive_cbk, shared_from_this(), std::placeholders::_1, std::placeholders::_2));
83 } else {
84 VSOMEIP_ERROR << "Error opening NETLINK socket!";
85 }
86}
87
88void netlink_connector::set_state(state_e _state) {
89 // This code is based on the assumption that it cannot be

Callers

nothing calls this directly

Calls 12

nl_protocolClass · 0.85
bufferClass · 0.85
messageMethod · 0.80
is_v4Method · 0.80
is_v6Method · 0.80
unlockMethod · 0.80
is_openMethod · 0.45
closeMethod · 0.45
openMethod · 0.45
bindMethod · 0.45
async_receiveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected