-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
When using rs-canopen-dump I frequently encountered these errors and the tool would exit:
read: can raw socket read: Resource temporarily unavailable
This is because a non-blocking socket is opened when using can_socket_open():
libcanopen/bin/rs-canopen-dump.c
Lines 49 to 50 in 6e4758b
| /* Create the socket */ | |
| if ((sock = can_socket_open(argv[1])) < 0) |
An alternate approach is to use can_socket_open_timeout() with a timeout of 0 instead:
diff --git a/bin/rs-canopen-dump.c b/bin/rs-canopen-dump.c
index 7b68661..7439799 100644
--- a/bin/rs-canopen-dump.c
+++ b/bin/rs-canopen-dump.c
@@ -47,7 +47,7 @@ main(int argc, char **argv)
}
/* Create the socket */
- if ((sock = can_socket_open(argv[1])) < 0)
+ if ((sock = can_socket_open_timeout(argv[1], 0)) < 0)
{
fprintf(stderr, "Error: Failed to create socket.\n");
return -1;This is consistent with how rs-canopen-monitor operates:
libcanopen/bin/rs-canopen-monitor.c
Lines 174 to 190 in 6e4758b
| /* Create the socket */ | |
| if ((sock = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) | |
| { | |
| fprintf(stderr, "Error: Failed to create socket.\n"); | |
| return -1; | |
| } | |
| /* Locate the interface you wish to use */ | |
| strcpy(ifr.ifr_name, argv[1]); | |
| ioctl(sock, SIOCGIFINDEX, &ifr); /* ifr.ifr_ifindex gets filled | |
| * with that device's index */ | |
| // XXX add check | |
| /* Select that CAN interface, and bind the socket to it. */ | |
| addr.can_family = AF_CAN; | |
| addr.can_ifindex = ifr.ifr_ifindex; | |
| bind(sock, (struct sockaddr*)&addr, sizeof(addr)); // XXX Add check |
Thanks for your work on libcanopen.
Metadata
Metadata
Assignees
Labels
No labels