summaryrefslogtreecommitdiffstats
path: root/CAN-binder
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-03 18:23:20 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-03 18:23:20 +0200
commit7679cd97dc4c20103f8afb364437dbcfd359befc (patch)
treeb39d54fab09797c38920155730bbedb4dd90393b /CAN-binder
parent1d2d57fea4a08f0a31eb207105abe7058bea4fcf (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')
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-bcm.cpp20
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-bcm.hpp2
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-raw.cpp22
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-raw.hpp2
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan.cpp14
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan.hpp2
6 files changed, 24 insertions, 38 deletions
diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
index cab9906..116b4c5 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());
diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp
index 63c728c..c0a1bb2 100644
--- a/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp
+++ b/CAN-binder/low-can-binding/utils/socketcan-bcm.hpp
@@ -38,7 +38,7 @@ namespace utils
{
public:
socketcan_bcm_t();
- socketcan_bcm_t(const socketcan_bcm_t&) = delete;
+ socketcan_bcm_t(const socketcan_bcm_t&);
socketcan_bcm_t(socketcan_bcm_t&&);
virtual ~socketcan_bcm_t();
diff --git a/CAN-binder/low-can-binding/utils/socketcan-raw.cpp b/CAN-binder/low-can-binding/utils/socketcan-raw.cpp
index 2c2b54e..23f8332 100644
--- a/CAN-binder/low-can-binding/utils/socketcan-raw.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan-raw.cpp
@@ -17,25 +17,25 @@
#include "socketcan-raw.hpp"
+#include <net/if.h>
+#include <sys/ioctl.h>
+
namespace utils
{
/// @brief Construct a default, invalid, socket.
socketcan_raw_t::socketcan_raw_t()
- : socketcan_t{}, socket_{INVALID_SOCKET}
+ : socketcan_t{}
{}
- /// @brief Construct a socket by moving an existing one.
- socketcan_raw_t::socketcan_raw_t(socketcan_raw_t&& s)
- : socket_{s.socket_}
- {
- s.socket_ = INVALID_SOCKET;
- }
-
/// @brief Destruct the socket.
socketcan_raw_t::~socketcan_raw_t()
+ {}
+
+ /// @brief Bind the socket.
+ /// @return 0 if success.
+ int socketcan_raw_t::bind(const struct sockaddr* addr, socklen_t len)
{
- if(socket_ != INVALID_SOCKET)
- ::close(socket_);
+ return socket_ != INVALID_SOCKET ? ::bind(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_RAW, CAN_RAW);
+ socket_ = socketcan_t::open(PF_CAN, SOCK_RAW, CAN_RAW);
// Attempts to open a socket to CAN bus
::strcpy(ifr.ifr_name, device_name.c_str());
diff --git a/CAN-binder/low-can-binding/utils/socketcan-raw.hpp b/CAN-binder/low-can-binding/utils/socketcan-raw.hpp
index 3c91029..71573da 100644
--- a/CAN-binder/low-can-binding/utils/socketcan-raw.hpp
+++ b/CAN-binder/low-can-binding/utils/socketcan-raw.hpp
@@ -24,7 +24,7 @@ namespace utils
{
public:
socketcan_raw_t();
- socketcan_raw_t(const socketcan_raw_t&) = delete;
+ socketcan_raw_t(const socketcan_raw_t&);
socketcan_raw_t(socketcan_raw_t&&);
virtual ~socketcan_raw_t();
diff --git a/CAN-binder/low-can-binding/utils/socketcan.cpp b/CAN-binder/low-can-binding/utils/socketcan.cpp
index 5a711c3..4d22654 100644
--- a/CAN-binder/low-can-binding/utils/socketcan.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan.cpp
@@ -83,20 +83,6 @@ namespace utils
return socket_ != INVALID_SOCKET ? ::setsockopt(socket_, level, optname, optval, optlen) : 0;
}
- /// @brief Bind the socket.
- /// @return 0 if success.
- int socketcan_t::bind(const struct sockaddr* addr, socklen_t len)
- {
- return socket_ != INVALID_SOCKET ? ::bind(socket_, addr, len) : 0;
- }
-
- /// @brief Connect the socket.
- /// @return 0 if success.
- int socketcan_t::connect(const struct sockaddr* addr, socklen_t len)
- {
- return socket_ != INVALID_SOCKET ? ::connect(socket_, addr, len) : 0;
- }
-
/// @brief Get the file descriptor.
/// @return The socket's file descriptor
int socketcan_t::socket() const
diff --git a/CAN-binder/low-can-binding/utils/socketcan.hpp b/CAN-binder/low-can-binding/utils/socketcan.hpp
index 391fb46..3c02a4f 100644
--- a/CAN-binder/low-can-binding/utils/socketcan.hpp
+++ b/CAN-binder/low-can-binding/utils/socketcan.hpp
@@ -34,7 +34,7 @@ namespace utils
{
public:
socketcan_t();
- socketcan_t(const socketcan_t&) = delete;
+ socketcan_t(const socketcan_t&);
socketcan_t(socketcan_t&&);
virtual ~socketcan_t();