diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-03 18:23:20 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-05-03 18:23:20 +0200 |
commit | 7679cd97dc4c20103f8afb364437dbcfd359befc (patch) | |
tree | b39d54fab09797c38920155730bbedb4dd90393b /CAN-binder/low-can-binding/utils/socketcan-bcm.cpp | |
parent | 1d2d57fea4a08f0a31eb207105abe7058bea4fcf (diff) |
Fix: constructor and include file missing.
Copy constructors are allowed since socket will never be closed during binding
runs.
Change-Id: Ie33e4b7e885d45e1ffeb980400df00ae2a97e45d
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/utils/socketcan-bcm.cpp')
-rw-r--r-- | CAN-binder/low-can-binding/utils/socketcan-bcm.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp index cab99067..116b4c57 100644 --- a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp +++ b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp @@ -17,6 +17,9 @@ #include "socketcan-bcm.hpp" +#include <net/if.h> +#include <sys/ioctl.h> + namespace utils { /// @brief Construct a default, invalid, socket. @@ -24,18 +27,15 @@ namespace utils : socketcan_t{} {} - /// @brief Construct a socket by moving an existing one. - socketcan_bcm_t::socketcan_bcm_t(socketcan_bcm_t&& s) - : socket_{s.socket_} - { - s.socket_ = INVALID_SOCKET; - } - /// @brief Destruct the socket. socketcan_bcm_t::~socketcan_bcm_t() + {} + + /// @brief Connect the socket. + /// @return 0 if success. + int socketcan_bcm_t::connect(const struct sockaddr* addr, socklen_t len) { - if(socket_ != INVALID_SOCKET) - ::close(socket_); + return socket_ != INVALID_SOCKET ? ::connect(socket_, addr, len) : 0; } /// @brief Open a raw socket CAN. @@ -47,7 +47,7 @@ namespace utils close(); struct ifreq ifr; - socket_ = open(PF_CAN, SOCK_DGRAM, CAN_BCM); + socket_ = socketcan_t::open(PF_CAN, SOCK_DGRAM, CAN_BCM); // Attempts to open a socket to CAN bus ::strcpy(ifr.ifr_name, device_name.c_str()); |