Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am writing a socket application program and trying to use non-block io.
Eveything works fine in the blocked mode. However, after I called the
ioctl (socketfd, FIONBIO, &on);
the following error occurs when I start the program.
I would say that now that you have set up a non-blocking socket, you would want to check whether your socket is ready for reading before trying to accept() on it. Otherwise, you will get such a "resource unavailable" error.
Use something like
Code:
if (FD_ISSET(listenfd, &read_fd)) {
len = sizeof(cliaddr);
connfd = Accept(listenfd, (SA *) &cliaddr, &len);
And put a pause in your loop. You seem to have requested a non-blocking socket, but have a loop which looks like it wants to block waiting for a socket request. (Also, the flag to the ioctl should be 1, as opposed to 0, to set it in non-blocking mode.)
The client could be blocking or non-blocking, depending on whether you want to wait for a connect() to complete. It does not have to be the same as the server.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.