How to avoid 'No buffer space available' on C socket?
Hello everybody,
Years ago i left in stand-by a project of mine where the main program was supposed to send thousands ARP frames over the socket as fast as it could; but because of a programming issue i couldn't continue it.
2 days ago I decided to solve that issue.
The thing is, when the program sends bunch of data, eventually it gives the error "No buffer space available". I increased the buffer space size and it gave more sending time, but it gave the same error message later. My question is, Is there a way to send bunch of data, fast and avoiding this socket error? I don't know, by freeing it, cleaning it, etc.
I'll appreciate any help, and please excuse my poor english.
Thank you.
It's not hard for a program to fill a buffer far faster than your network can send data. That is why you're running out of buffer. You'll just have to trust the OS to send the data as fast as it can, unless you feel like writing your own driver.
And isn't there a way to avoid this? I don't know... Increasing socket sending time or reducing it by SO_RCVTIMEO or SO_SNDTIMEO.
I don't care if my program has to hang a little bit between sending blocks, I just don't want it to close because of the socket error.
---------- Post updated at 06:34 PM ---------- Previous update was at 05:21 PM ----------
Corona688, You gave me the answer... TIME.
If my socket overloads its buffer it crashes, so, I solved it giving it time in this way:
So, if my socket runs out of buffer space while sending, it waits some nsecs, and then goes to the label where it retries to send the message. I don't know if this ain't the best way to avoid it, but keeping it simple, It works!.
Thanks everybody for your help!
As always, the best place on the Internet to ask for a good programming advice is here.
Usually you would leave the socket as blocking, so that when the buffer fills, your program waits. If you can't trust the OS to transmit as fast as possible, then you're stuck either way, since you can't not use the OS...
Last edited by Corona688; 10-21-2013 at 01:53 PM..
I need clarification on whether it is okay to set socket options on a listening socket
simultaneously when it is being used in an accept() call?
Following is the scenario:-
-- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
consider the small piece of code
while read line
do
echo $line
done < example
content of example file
sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr
the output is like
sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr
the... (4 Replies)
I recently started working with Linux and wrote my first device driver for a hardware chip controlled by a host CPU running Linux 2.6.x kernel.
1. The user space process makes an IOCTL call with pointer to a user memory buffer.
2. The kernel device driver in the big switch-case of IOCTL,... (1 Reply)
Hello,
I'm doing a very simple program which reads a file and sends whatever is in the file through a socket. Like the program "file2cable".
Let's say i have a file containing the following, which is a hex dump of an ARP request frame:
ff ff ff ff ff ff 00 1b 24 79 5a 73 08 06
00 01 08... (5 Replies)
I have set the receive buffer size of socket to max.
setsockopt(sd,SOL_SOCKET, SO_RCVBUF,&max,optval);
Am reading data from the socket in a loop(say max 100 bytes per recv)
while(1)
{
int rlen=recv(sd,(void *)buf, 100 , 0);
//err handle and processing
}
Assume my process is slow... (2 Replies)
Hi,
I have some problem with following command.
$path='pwd'.”/pack”;
When I check the value in the variable path , it give the following output
/tmp/new /pack
The pwd will be /tmp/new
Now the problem is the spaces is added between pwd and the appended path.
I need the output like... (5 Replies)
Hi,
I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime.
To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
If I run the following command remotely after ssh than it works fine
su - oracle -c "/oracle/product/102/db/bin/dbshut"
But If I run the following command it doesn't work
su - oracle -c "/oracle/product/102/db/bin/lsnrctl stop"
Because I think there is a space is present between lsnrctl and... (1 Reply)
When I worked with client-server (socket) programming, I encountered "the socket error# 10055" which means "No buffer space available". This might be a symptom of one or more applications that didn't return system resources (like memory) properly. Temporary solution was to reboot the machine to... (7 Replies)