I've opened the CAN-Socket in this way:
Code: Select all
if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("CanSend: Error while opening socket");
exit(-1);
}
strcpy(ifr.ifr_name, ifname.c_str());
ioctl(s, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("CanSend: Error in socket bind");
exit(-2);
}
Writing in a separate thread getting the packages from a shared queue:
Code: Select all
bytes_written = write(t->s, frame.get(), sizeof(struct can_frame));
The first time that block occurs it's usually about 30s, and after a while its a 2-3s block, every 15-20s.
I'm using the PCAN-FD USB interface.
I'm running this on a CentOS (Kernel 4.18.0-147.8.1.el8_1.x86_64) with gcc v8.3.1