简体   繁体   中英

ERROR on accept: Resource temporarily unavailable

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.

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.

也许,在accept()之后设置fnctl标志可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM