assign an event to a socket operation
-
Windows 7, Visual Studio 2012, winsock Edit: Oops, posted in ATL rather than C++. If you are an admin type, please move it. How is an event associated with a socket operation? For example: [code]
// start listening for new clients attempting to connect
iResult = listen(ListenSocket, 1);[/code] The socket is non-blocking and the code continues while waiting for the listen operation to complete. I want event: CLIENT_DETECTED (arbitrary name, I know how to create the event.) to be triggered when a client solicits a connection. Yes, I understand a bunch of code is needed to capture that event and do something. Thank you for your time.
-
Windows 7, Visual Studio 2012, winsock Edit: Oops, posted in ATL rather than C++. If you are an admin type, please move it. How is an event associated with a socket operation? For example: [code]
// start listening for new clients attempting to connect
iResult = listen(ListenSocket, 1);[/code] The socket is non-blocking and the code continues while waiting for the listen operation to complete. I want event: CLIENT_DETECTED (arbitrary name, I know how to create the event.) to be triggered when a client solicits a connection. Yes, I understand a bunch of code is needed to capture that event and do something. Thank you for your time.
-
See http://msdn.microsoft.com/en-gb/library/windows/desktop/ms739168(v=vs.85).aspx[^],
listen
is a blocking call.Hello, OK, its there as in:
Quote:
Note When issuing a blocking Winsock call such as listen, Winsock may need to wait for a network event before the call can complete.
I presumed that it could also be non-blocking. Then they carry on with:
Quote:
Winsock performs an alertable wait in this situation, which can be interrupted by an asynchronous procedure call (APC) scheduled on the same thread.
So in order to kill the program when no client comes a-calling, I need to learn this. I will search but if you have a link to a good article on this, that would be appreciated. Thank you for your time. Edit: While re-reading the MSDN page on listen(), I noticed that the words are:
Quote:
... Winsock may need to wait for a network event....
Directing attention to the word "may," that means that there are circumstances in which Winsock does not need to wait for a network event. Should that statement have stated that Winsock "will" wait for a network event? Or is there another way out of the Listen call?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
Hello, OK, its there as in:
Quote:
Note When issuing a blocking Winsock call such as listen, Winsock may need to wait for a network event before the call can complete.
I presumed that it could also be non-blocking. Then they carry on with:
Quote:
Winsock performs an alertable wait in this situation, which can be interrupted by an asynchronous procedure call (APC) scheduled on the same thread.
So in order to kill the program when no client comes a-calling, I need to learn this. I will search but if you have a link to a good article on this, that would be appreciated. Thank you for your time. Edit: While re-reading the MSDN page on listen(), I noticed that the words are:
Quote:
... Winsock may need to wait for a network event....
Directing attention to the word "may," that means that there are circumstances in which Winsock does not need to wait for a network event. Should that statement have stated that Winsock "will" wait for a network event? Or is there another way out of the Listen call?
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
bkelly13 wrote:
Should that statement have stated ...
I cannot answer for Microsoft's wording. My reading of it is that
listen
always blocks for a connection to complete, it should not be too difficult to test.I am going with that. Thank you for taking the time to reply.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com
-
bkelly13 wrote:
Should that statement have stated ...
I cannot answer for Microsoft's wording. My reading of it is that
listen
always blocks for a connection to complete, it should not be too difficult to test.I have finally progressed to the point of testing the listen() function. This app sets non-blocking attribute and the code steps right over the listen() call, with a noticeable pause. Now the question becomes: Is there a proper method of stopping a listen in progress? There are WSASend() and other socket methods with additional arguments, but I did not find a WSAListen(); I will post that as a new question.
Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com