summaryrefslogtreecommitdiffstats
path: root/low-can-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-12-06 09:38:05 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2020-01-09 16:25:36 +0100
commit4022a03b70337f6f922e97fb2f77d28058612587 (patch)
tree8d64103da870aa3f250cffc4da0e302850263c47 /low-can-binding
parent0ff6413b6dc42849f87ce8caa17a91f44ede2f93 (diff)
socket-bcm: Format, simplification of open socket
Change-Id: I8a012285a8d06f3c5778c82e543c944d8fa20e3c Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding')
-rw-r--r--low-can-binding/utils/socketcan-bcm.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/low-can-binding/utils/socketcan-bcm.cpp b/low-can-binding/utils/socketcan-bcm.cpp
index 515b2fb3..a5820434 100644
--- a/low-can-binding/utils/socketcan-bcm.cpp
+++ b/low-can-binding/utils/socketcan-bcm.cpp
@@ -38,6 +38,7 @@ namespace utils
socket_ = socketcan_t::open(PF_CAN, SOCK_DGRAM, CAN_BCM);
// Attempts to open a socket to CAN bus
+ tx_address_.can_family = AF_CAN;
::strcpy(ifr.ifr_name, device_name.c_str());
AFB_DEBUG("BCM socket ifr_name is : %s", ifr.ifr_name);
if(::ioctl(socket_, SIOCGIFINDEX, &ifr) < 0)
@@ -46,19 +47,17 @@ namespace utils
close();
return -1;
}
- else
+
+ tx_address_.can_ifindex = ifr.ifr_ifindex;
+ if(connect((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
{
- tx_address_.can_family = AF_CAN;
- tx_address_.can_ifindex = ifr.ifr_ifindex;
-
- if(connect((struct sockaddr *)&tx_address_, sizeof(tx_address_)) < 0)
- {
- AFB_ERROR("Connect failed. %s", strerror(errno));
- close();
- }
- // Needed because of using systemD event loop. See sd_event_add_io manual.
- fcntl(socketcan_t::socket_, F_SETFL, O_NONBLOCK);
+ AFB_ERROR("Connect failed. %s", strerror(errno));
+ close();
+ return -1;
}
+ // Needed because of using systemD event loop. See sd_event_add_io manual.
+ fcntl(socketcan_t::socket_, F_SETFL, O_NONBLOCK);
+
return socket_;
}
@@ -101,7 +100,6 @@ namespace utils
int socketcan_bcm_t::write_message(message_t& m)
{
-
can_message_t& cm = reinterpret_cast<can_message_t&>(m);
struct bcm_msg obj = cm.get_bcm_msg();
size_t size = (obj.msg_head.flags & CAN_FD_FRAME) ?