The CAN setup under linux has a lot of problems. Here's my previous research on this.
I don't know if the problem you're having is related to the transmit queue block-and-drop limits, but it might be.
Even if it isn't, this information might be useful for someone else.
http://socket-can.996257.n3.nabble.com/Solving-ENOBUFS-returned-by-write-td2886.html
With Ethernet, the transmit queue length is 1000 (which would return ENOBUF) but before that happens it hits SO_SNDBUF, which may be 108544, which is the total Data plus SKB, and with an SKB size of about 200 that means it blocks at about 500 before it ENOBUFs at 1000.
With CAN, it would block at 500, but it ENOBUFs at 10 first!
The blocking limit could be introduced/reduced by setting the SO_SNDBUF socket option.
If we set that limit to a suitable multiple of the socket size (say 5 by 200 or 1000 bytes) then it would probably block before it ENOBUFed.
The recommended ENOBUF recovery method is "retry after a short sleep", in this case at least 100us.
Here's another one:
http://rtime.felk.cvut.cz/can/socketcan-qdisc-final.pdf
Blocking the application when the queue is full
Many SocketCAN users experience a problem with write()/send()
failing with -ENOBUFS error. Since this is related to the use of queueing
disciplines, this section describes why it happens and what can be done
against it. In the default con?figuration, CAN interfaces have attached
pfifo fast queuing disci-pline which, when enqueueing the packet,
checks whether the number of queued packets is greater then dev->txqueuelen
(which is 10 for CAN devices by default). If it is the case, it returns
NET_XMIT_DROP which is translated to -ENOBUFS in net_xmit_errno()
called from can_send().
The problem is, that there is no way for the application to be
blocked until the queue becomes empty again. How can be the application
made to block when the queue is full instead of getting ENOBUFS
error? In general there are two mechanisms that limit the number of queued
packets. First, there is the already mentioned per-device tx_queue_len
limit and second, the per-socket SO_SNDBUF limit. The application only
blocks when the latter limit is reached. Therefore, the solution is to set
SO_SNDBUF low enough that this limit is reached before tx_queue_len limit.
Now, the question is to which value set the SO_SNDBUF limit. First,
the minimum value is SOCK_MIN_SNDBUF/2, i.e. 1024. When the user
supplies a smaller value the minimum is used instead. The more
tricky thing is how is the value interpreted. The value represents
the maximum socket send bu?er in bytes. The kernel always doubles
the value supplied by user (i.e. for the kernel the minimum is 2048)
and stores it in sk->sk_sndbuf. When a packet is sent, a per-socket
counter is increased by sizeof(can_frame) + sizeof(skb) (which is a
value around 200, depending on kernel con?guration and architecture). When
the counter is greater or equal to sk->sk_sndbuf, the application blocks.
The following piece of code sets the SO_SNDBUF value to its minimum:
int sndbuf = 0; if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sndbuf,
sizeof(sndbuf)) < 0) perror("setsockopt");
Typically, the minimum value causes the application to block when there are about
15 frames queued. If we want all CAN applications in the system to block instead
of receiving ENOBUFS, it is necessary to set the txqueuelen (see Section
3.1.2) to the number of simultaneously used CAN sockets in the system
multiplied by 15. If the application does not wish to block, it sets
O_NONBLOCK flag on the socket by using fcntl() call. After that, when the
SO_SNDBUF is reached, the application receives EAGAIN error instead of
ENOBUFS
Tom