TCP - C/C++ - accept() - exitting application

Started by
6 comments, last by hplus0603 18 years, 7 months ago
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!
STOP THE PLANET!! I WANT TO GET OFF!!
Advertisement
Set the socket to nonblocking and handle EAGAIN error codes.

Look at the accept man page :-)
Winterdyne Solutions Ltd is recruiting - this thread for details!
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.
http://www.p2pmud.com
Yup, select() is the way I'd go.
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.
STOP THE PLANET!! I WANT TO GET OFF!!
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
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.
STOP THE PLANET!! I WANT TO GET OFF!!
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.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement