Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR on accept: Resource temporarily unavailable

Tags:

c

linux

sockets

I am trying to create single threaded server in linux (red-hut) in C that will listen to multiple sockets.

I need to use non-blocking sockets, when I set the flags to non-blocking like this:

int flagss = fcntl(socketfds[j],F_GETFL,0); 
flagss |= O_NONBLOCK;
fcntl(socketfds[j],F_SETFL,flagss);

I get:

ERROR on accept: Resource temporarily unavailable

Otherwise everything works perfectly.

like image 882
oznus Avatar asked Oct 03 '11 13:10

oznus


1 Answers

Resource temporarily unavailable is EAGAIN and that's not really an error. It means "I don't have answer for you right now and you have told me not to wait, so here I am returning without answer."

If you set a listening socket to non-blocking as you seem to do, accept is supposed to set errno to that value when there are no clients trying to connect. You can wait for incoming connection using the select (traditional) or poll (semantically equivalent, newer interface, preferred unless you need to run on some old unix without it) or epoll (optimized for thousands of descriptors, Linux-specific) system calls.

Of course you will be using poll (or any of the alternatives) to wait for data on the listening socket or any of the data sockets.

like image 141
Jan Hudec Avatar answered Oct 17 '22 16:10

Jan Hudec