Sponsored Content
Top Forums Programming How to avoid 'No buffer space available' on C socket? Post 302863323 by Zykl0n-B on Sunday 13th of October 2013 10:34:28 PM
Old 10-13-2013
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:

Code:
while(time(NULL) - startTime < (time_assigned * 60))
{
 retry: /*This is a label.*/
 ret = sendto(sock, &arpmsg, sizeof(struct arpmsg),0, &sockaddr,sizeof(sockaddr));

    if(ret < 0) 
        {
           if(errno == ENOBUFS)
            {
              printf("Socket ran out of buffer space.\n");
              printf("Giving it some time...\n");
              usleep(300000);
              goto retry;
             }else {
                       perror("sendto()");
                       exit(-1);
                       }
         }
        checkordersarrival();
        }
}

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. Smilie
Zykl0n-B
 

10 More Discussions You Might Find Interesting

1. Programming

how to clear/clean mbufs (network buffer space)?

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)
Discussion started by: dipti
7 Replies

2. Linux

ssh: connect to host traviata port 22: No buffer space available

What does that mean? traviata being my distant host? What am i to do? (0 Replies)
Discussion started by: penguin-friend
0 Replies

3. Shell Programming and Scripting

how to avoid space to run remotely

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)
Discussion started by: madhusmita
1 Replies

4. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

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)
Discussion started by: chandrutiptur
0 Replies

5. Shell Programming and Scripting

How to avoid the space

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)
Discussion started by: kalpeer
5 Replies

6. Programming

Finding used socket receive-buffer size

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)
Discussion started by: johnbach
2 Replies

7. Programming

Store file into a buffer to send it through a socket

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)
Discussion started by: semash!
5 Replies

8. Linux

Linux Device Driver: avoid mem copy from/to user/kernel space

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)
Discussion started by: agaurav
1 Replies

9. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

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)
Discussion started by: Kesavan
4 Replies

10. IP Networking

Clarification - Setting socket options at the same time when socket is listening

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)
Discussion started by: jake24
2 Replies
SEND(2) 						      BSD System Calls Manual							   SEND(2)

NAME
send, sendto, sendmsg -- send a message from a socket SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> ssize_t send(int s, const void *msg, size_t len, int flags); ssize_t sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, int tolen); ssize_t sendmsg(int s, const struct msghdr *msg, int flags); DESCRIPTION
Send(), sendto(), and sendmsg() are used to transmit a message to another socket. Send() may be used only when the socket is in a connected state, while sendto() and sendmsg() may be used at any time. The address of the target is given by to with tolen specifying its size. The length of the message is given by len. If the message is too long to pass atomically through the underlying protocol, the error EMSGSIZE is returned, and the message is not transmitted. No indication of failure to deliver is implicit in a send(). Locally detected errors are indicated by a return value of -1. If no messages space is available at the socket to hold the message to be transmitted, then send() normally blocks, unless the socket has been placed in non-blocking I/O mode. The select(2) call may be used to determine when it is possible to send more data. The flags parameter may include one or more of the following: #define MSG_OOB 0x1 /* process out-of-band data */ #define MSG_DONTROUTE 0x4 /* bypass routing, use direct interface */ The flag MSG_OOB is used to send ``out-of-band'' data on sockets that support this notion (e.g. SOCK_STREAM); the underlying protocol must also support ``out-of-band'' data. MSG_DONTROUTE is usually used only by diagnostic or routing programs. See recv(2) for a description of the msghdr structure. RETURN VALUES
The call returns the number of characters sent, or -1 if an error occurred. ERRORS
Send(), sendto(), and sendmsg() fail if: [EBADF] An invalid descriptor was specified. [ENOTSOCK] The argument s is not a socket. [EFAULT] An invalid user space address was specified for a parameter. [EMSGSIZE] The socket requires that message be sent atomically, and the size of the message to be sent made this impossible. [EAGAIN] The socket is marked non-blocking and the requested operation would block. [ENOBUFS] The system was unable to allocate an internal buffer. The operation may succeed when buffers become available. [ENOBUFS] The output queue for a network interface was full. This generally indicates that the interface has stopped sending, but may be caused by transient congestion. [EACCES] The SO_BROADCAST option is not set on the socket, and a broadcast address was given as the destination. [EHOSTUNREACH] The destination address specified an unreachable host. SEE ALSO
fcntl(2), recv(2), select(2), getsockopt(2), socket(2), write(2) HISTORY
The send() function call appeared in 4.2BSD. 4.2 Berkeley Distribution February 21, 1994 4.2 Berkeley Distribution
All times are GMT -4. The time now is 05:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy