>  I have an application where I want to break out an event, and
>exit the thread. I have the following:

> WSAEVENT hEvent = WSA_INVALID_EVENT;
> hEvent = WSACreateEvent();
> ::WSAEventSelect(CSock.m_Connection, hEvent, FD_ACCEPT);

>but at any point within the application I want to break the thread,
>and stop any other connections, then restart the  thread again at
>any time.

>From MSDN on WSAEventSelect():

"Closing a socket with closesocket also cancels the association and
selection of network events specified in WSAEventSelect for the socket. The
application, however, still must call WSACloseEvent to explicitly close the
event object and free any resources."

It seems you can simply close the socket, then call WSACloseEvent(), and it
should be OK to end the thread?

You can call ::WSAEventSelect(CSock.m_Connection, hEvent, 0) first, if that
make it seem less like pulling the power cord out {;v)

Of course, if you have started waiting on that event, then I guess you
should use WSASetEvent() to set it to signalled (thus ending the wait), and
carefully check the result from the Wait call to find out that it was
cancelled rather than because you had an accept...

--
Jason Teagle
[EMAIL PROTECTED]



_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for 
subscription changes, and list archive.

Reply via email to