Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unblock a Blocked Winsock accept() Call

Tags:

winsock

I am using Winsock under VS 2008.

I have a thread dedicated to accepting incoming TCP connection requests via a blocking call to accept(). When the time comes for my app to shut down, I need to somehow unblock this thread so it can perform its shutdown work and exit. Is there a way I may unblock accept()?

I will post another question in case there is no way to unblock accept(). That question is: If I perform a hard kill of the thread that is blocked on accept(), will anything bad happen (corruption of OS data structures, etc.)?

Thanks, Dave

like image 318
Dave Avatar asked Jan 03 '12 17:01

Dave


1 Answers

One way to unblock a blocking accept() is to close the listening socket from another thread. Otherwise, you can put the listening socket into non-blocking mode and use select() (which does support a timeout) to detect when accept() can be called without blocking.

like image 87
Remy Lebeau Avatar answered Sep 29 '22 03:09

Remy Lebeau