Sending messages with a CAN socket : no error but message not sent?

  c++, can-bus, socketcan

I’m trying to write a program (in C/C++) that sends CAN messages from a Raspberry Pi 3B+ (with an image made with buildroots) with a PiCAN2 shield to another device. I open and bind a CAN socket and send a message using the write function just as in this example :

My problem is : the program terminates without any error but it seems like the CAN frame is never sent. It is not acknowledged by my other device and I cannot see it with candump (even if I set my can bus in loopback mode for debug purposes). But the write function tells me that all the message has been sent.

When I use cansend directly, the frame is correctly received and acknowledged by the other device, and I can see it with candump. Moreover, after using my program and trying to send a CAN frame with it, the frames sent with cansend are not visible in candump anymore. So, I suspect the message I try to send with my program is blocking something ?

As using cansend worked, I try to copy/paste its code in my program, but I get the same result (I cannot see the message on the can bus).

Does anyone have any idea on where my messages are going or are stucked ?

Thank you for your help !

Source: Windows Questions C++