Hi there, I guessing that I probably dont have some library so gcc gives this error:
erro: 'EAGAIN' undeclared (first use in this function)
Can you tell what am I doing wrong?
Thanks in advance
Printable View
Hi there, I guessing that I probably dont have some library so gcc gives this error:
erro: 'EAGAIN' undeclared (first use in this function)
Can you tell what am I doing wrong?
Thanks in advance
Code:#include <errno.h>
hi again, i am doing a non-blocking server...So I put theinside aCode:accept
and each timeCode:for
it creates a new thread, passing in it the socket descriptor of accepted client.Code:accept>0
I set.Code:socket(PF_INET, SOCK_STREAM || SOCK_NONBLOCK, IPPROTO_TCP)
Can you give me some hints to put the accept in a non-bloking mode? Probably I have to test the accept with the flag EWOULDBLOCK., but I am having some dificulties on setting this up.
Thanks in advance
PS: this is because I want to do more things inside that for...
Well is the first problem solved or not?
I would read this link (especially the bottom), and relevant man pages:
- Blocking vs. non-blocking sockets
- socket(7): socket interface - Linux man page
- fcntl(2): change file descriptor - Linux man page
One thing in particular is that all of these links mention "O_NONBLOCK", and never "SOCK_NONBLOCK".
I guess i am having some troubles with error messages. In accept(2) man pages it says that SOCK_NONBLOCK flag will save extra calls to fcntl. So far so good... I set that up and now I simple dont know how to test if accept will block or not.
Any hints??
Cant you just do an "accept" and do a printf statement to see if it continues immediately after the "accept" statement and prints the message, before a client connects? Make sure to print to "stderr", so use "fprintf" to do so (because stderr is unbuffered, so all messages get printed immediately).
I havent done anything with sockets in a while now, so maybe Im just not understanding what the problem is.
Not in mine it doesn't! Please quote this. Also, there is no flags parameter to accept().
Anyway, if the socket is set NON_BLOCK, accept() will not block -- you do not have to test that.
If you want to test if the socket was successfully set non-block, just do this:
Now run the program, but don't try to connect to it. If HEY appears right away, you are in non-blocking mode. Otherwise, execution will wait for accept to accept something.Code:accept(....);
puts("HEY");
Okay. This is very very non-standard tho, since I am running glibc 2.9 (fedora 10-64) and accept4 does not exist here, so it probably will not be available on 95%+ of linux systems. Whereas accept() and fcntl() are available anywhere you have C.
Use of fcntl() for this is pretty straightforward:
Code:fcntl(sock,F_SETFL,O_NONBLOCK);
Problem solved...Its runnig all ok. Thanks for your help :D