fix: test for opened CAN socket.
authorRomain Forlot <romain.forlot@iot.bzh>
Mon, 13 Mar 2017 08:02:45 +0000 (09:02 +0100)
committerRomain Forlot <romain.forlot@iot.bzh>
Thu, 16 Mar 2017 16:14:37 +0000 (17:14 +0100)
Change-Id: If9e3a0511c7ccc703817069a56bd38d7e64ebb09
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
src/can/can-bus-dev.cpp

index 3aafff3..5c8673c 100644 (file)
@@ -100,7 +100,7 @@ int can_bus_dev_t::open()
                }
                close();
        }
-       else ERROR(binder_interface, "socket could not be created. Error was : %s", ::strerror(errno));
+       else ERROR(binder_interface, "open: socket could not be created. Error was : %s", ::strerror(errno));
        return -1;
 }
 
@@ -117,9 +117,9 @@ can_message_t can_bus_dev_t::read()
        struct canfd_frame cfd;
 
        // Test that socket is really opened
-       if (can_socket_)
+       if (!can_socket_)
        {
-               ERROR(binder_interface, "read_can: Socket unavailable. Closing thread.");
+               ERROR(binder_interface, "read: Socket unavailable. Closing thread.");
                is_running_ = false;
        }
 
@@ -180,7 +180,7 @@ int can_bus_dev_t::send(can_message_t& can_msg)
 
        f = can_msg.convert_to_canfd_frame();
 
-       if(can_socket_.socket())
+       if(can_socket_)
        {
                nbytes = ::sendto(can_socket_.socket(), &f, sizeof(struct canfd_frame), 0,
                        (struct sockaddr*)&txAddress_, sizeof(txAddress_));
@@ -211,7 +211,7 @@ bool can_bus_dev_t::shims_send(const uint32_t arbitration_id, const uint8_t* dat
        f.len = size;
        ::memcpy(f.data, data, size);
 
-       if(can_socket_.socket())
+       if(can_socket_)
        {
                nbytes = ::sendto(can_socket_.socket(), &f, sizeof(struct canfd_frame), 0,
                        (struct sockaddr*)&txAddress_, sizeof(txAddress_));