Jason E. Jason E. - 2 months ago 5
C++ Question

Why does the socket accept function not release after closesock called?

I have a server application that opens a socket and listen for a connection. In the application, I have a separate thread that creates a socket, binds it and calls the listen and accept functions on it.

When the application closes I call closesocket on the socket that was created, then wait for the socket thread to close. However, if the thread is waiting on the accept function the thread never completes.

I thought that the accept function would return after the cloasesocket was called. Is this a correct thought? If so, why does the accept function not return? Is there another way to cause the accept function to return?


Don't call accept unless select says it's OK. In that case accept will never block.