TCP - C/C++ - accept() - exitting application
I have a bit of a problem with the accept() function when closing my application: it doesn't fall through. In my connection loop I keep waiting for new connections where the accept() blocks untill a new connection comes in. But when closing down I need the accept() to fall through without there being a new connection, so my thread can exit nicely.
How do I make the accept() fall through in a nice manner? Is there a way to "kill" it?
Thanks!
Set the socket to nonblocking and handle EAGAIN error codes.
Look at the accept man page :-)
Look at the accept man page :-)
if u set your flags right on select() you can tell when a new connection is pending, and you should only call accept() when this is the case.
I was unaware select would fall through when a new connection was pending. I'll do some looking up on that subject then.
Thank you.
Thank you.
I should think that if you close the listening socket, a blocking accept() should come back with an error. Try it to see if it works.
Mark
Mark
Quote:Original post by markr
I should think that if you close the listening socket, a blocking accept() should come back with an error. Try it to see if it works.
Mark
This is indeed the case under Windows, but under VxWorks (and I believe LynxOS too) this does not work. I could not find any resources on the Berkeley Sockets that specifies this behaviour.
The threading behavior of sockets varies by OS (and by WinSock version on Windows -- make sure you use version 2.2 !)
On UNIX-alikes, you probably would want to unblock the thread by sending it a signal.
On UNIX-alikes, you probably would want to unblock the thread by sending it a signal.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement