Socket write avoiding No buffer space available

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
agecheris
Posts: 4
Joined: Fri 14. Apr 2017, 14:19

Socket write avoiding No buffer space available

Post by agecheris » Fri 14. Apr 2017, 14:26

Hi,
I am using the PCAN adapter with the 8.1 Linux driver in Ubuntu 16.04. I have implemented SocketCAN support in my application but when writing I get errno=105 "No buffer space available". How can I avoid this?

I have been reading about different calls of setsockopt, ioctl etc but I cannot find any information on how to determine the free space of the write buffer. Any help is appreciated.

Thanks

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Socket write avoiding No buffer space available

Post by S.Grosjean » Wed 19. Apr 2017, 10:03

Hi,

There's many reasons why the socketCAN layer cannot flush its internal buffers.
First of all, please give us the result of "cat /proc/pcan" as well as "uname -a".

You might also install the last version of pcan from here:
http://www.peak-system.com/fileadmin/me ... 3.1.tar.gz

Regards,

Stéphane
— Stéphane

agecheris
Posts: 4
Joined: Fri 14. Apr 2017, 14:19

Re: Socket write avoiding No buffer space available

Post by agecheris » Wed 19. Apr 2017, 18:31

Hi Stéphane,
Thank you for the reply. Here comes the requested information.
I dont think there is any problem with the Peak related stuff.
I just want to know how the determine the state of the tx buffer.
This is maybe more related to SocketCAN than Peak.

If I increase the tx buffer like this "ifconfig can0 up txqueuelen 500"
I dont get the 105 error. It seems to default to 10. I guess that it is 10 frames.
But in my application I want to be able to handle the case when the tx buffer gets full whatever the its size is.

cat /proc/pcan
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20170214_n (8.3.1) Apr 19 2017 20:28:49 --------------
*---------- [mod] [isa] [pci] [pec] [dng] [par] [usb] [pcc] [net] -----------
*--------------------- 1 interfaces @ major 246 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32 usb can0 ffffffff 002 0x001c 00000000 00000000 00000000 00000000 0x0000

uname -a
Linux mikael-VirtualBox 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:23 UTC 2017 i686 i686 i686 GNU/Linux

Thanks

agecheris
Posts: 4
Joined: Fri 14. Apr 2017, 14:19

Re: Socket write avoiding No buffer space available

Post by agecheris » Wed 19. Apr 2017, 20:40

With the latest driver I dont get the error, even with txqueuelen=1. But my request remain. I would like to write robust code but I dont know how to get the status of the tx buffer.

M.Maidhof
Support
Support
Posts: 1751
Joined: Wed 22. Sep 2010, 14:00

Re: Socket write avoiding No buffer space available

Post by M.Maidhof » Thu 20. Apr 2017, 09:53

Hi,

do you use a virtual machine? Then this buffer problem could be related to your Virtual Box USB system Please check that all “guest extension packs” are installed on that VM. We don´t support VM related problems. So please test again in a native Linux system, to see if that problem is based on the virtual system.

regards

Michael

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Socket write avoiding No buffer space available

Post by S.Grosjean » Thu 20. Apr 2017, 10:11

Hi,

Thx for your feedback. AFAIU you're running a Linux system into a virtual box, with a PCAN-USB device connected to. We generally do not support such configuration and generally strongly advice to move on a real Linux machine.

To answer to your request: socket-CAN is (obviously) a socket-based API. There is actually no way to determine the status of the Tx buffer, because socket are historically IP medium oriented. Using the sockets with IP protocols means: 1/ using UDP and thus, knowing that some datagrams may be lost 2/ using TCP and thus, trusting in the (socket) protocol layers to handle lost and/or out-of-order packets. In both cases, Tx buffer size is no longer an issue.

Thus, the only way of controlling CAN frames sending is to handle errno=105 by yourself, then, setting up some (not busy) wait cycles before retrying the same "send()" command. You can have a look to the cansend.c application from the can-utils package to learn more about that.

Regards,

Stéphane
— Stéphane

agecheris
Posts: 4
Joined: Fri 14. Apr 2017, 14:19

Re: Socket write avoiding No buffer space available

Post by agecheris » Thu 20. Apr 2017, 10:17

Thank you very much for the help. Case closed. I will handle any tx buffer full in my application.

Post Reply