Hi,
The below works fine, cheers.

The below stops all further connections but, when my program initialises I do the below:

WHen I exit the thread, my previous email, things work, but I want to stop all further connections,then restart them later. As the thread is now exited, I now have to closethe original socket below. But do I unbind (if exists) the below, then stop listen(..) . If I do this, how do I do it? and how would I restart it again.

Regards
Neil
///////////////////////////
MY CODE:

struct sockaddr_in sin; /* an Internet endpoint address  */
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(PortNo);

char tmp[100];

   /* Allocate a socket */
m_Connection = WSASocket(AF_INET, SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED);

   /* Bind the socket */
if (bind(m_Connection, (struct sockaddr *)&sin, sizeof(sin)) == SOCKET_ERROR)
{
 sprintf(tmp,"can't bind to port: %d", PortNo);
 AfxMessageBox(tmp);
 return false;
}

if (listen(m_Connection, qlen) == SOCKET_ERROR)
{
 sprintf(tmp,"can't listen on port: %d", PortNo);
 AfxMessageBox(tmp);
 return false;

}

----- Original Message ----- From: "Jason Teagle" <[EMAIL PROTECTED]>
To: <msvc@BeginThread.com>
Sent: Friday, June 10, 2005 6:23 PM
Subject: RE: [msvc] breaking out from an event.


 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
msvc@beginthread.com
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.




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

Reply via email to