Hi Douglas, and all,
I had a look at that example and it doesnt seem to deal with unexpected
remote socket closure :-(
Meaning, it doesnt use WSAEventSelect or WSAAsyncSelect to detect when
clients "unexpectedly" close their end of the socket connection.
Under typical web proxy operating conditions I dont have a problem, eg:
A browser connects to my proxy, sends a HTTP request, proxy recieves
request, retrieves page from server, sends to client, and then disconnects
socket.
It's when a browser connects, send the http request and then closes the
socket without waiting for a reply. I can reproduce this by pressing the
refresh button
many times quickly. I get all the connect/receive notifications, but after
the proxy has retrieved the web page and then trys to WSASend() it to the
client i DONT receive a completion, and no error either!
Please anyone, whats the best method of detecting remote socket close, when
using IOCP with a pool of 500 (or greater) listening sockets?
Surely not an event per socket, because that would cost me 500/64 threads (1
thread per 64 event handles) to monitor all those events?
If i register interest in FD_CLOSE for all the sockets using the same
WSAEvent, how would i "efficiently" identify the socket which had been
closed from the single event? Surely not by calling WSAEnumNetworkEvents()
for each of my connected sockets?
Please any advice would be very welcome, thanks,
Darren
> Check out the sockhim program found here:
> http://www.mvps.org/win32/index.html
> It's under "Sockets, IOCPs, AcceptEx" in the index.
> I've used that as a model to create a server and (as yet) have not had any
> problems detecting closure. Let me know what you think as I'm still
pretty
> green.
> > Hi,
> > Q. How can you detect when a socket has been closed remotely, when using
> > IOCP?
> > I know that with tradition blocking sockets you perform a ::recv which
> > returns 0 if the socket has been remotely closed.
> > I dont want to do this because the non-blocking socket i am checking
> already
> > has an outstanding WSASend/WSARecv operation, for which no completion
has
> > been received (for quite some time).
> > ______Context______
> > Ive written a web proxy using IOCP, it contains a pool of listening
> sockets.
> > My code is loosley based on the article: "Windows Sockets 2.0: Write
> > Scalable Winsock Apps Using Completion Ports" from
> > http://msdn.microsoft.com/msdnmag/issues/1000/Winsock/Winsock.asp
> > If i continually hit refresh on my browser - generating a lot of proxy
> > requests, i've noticed some sockets on my proxy never seem to recieve
> > completion notifications, indefinitely. I put this down to the browser
> > closing sockets (on which a request has been made but a response has not
> yet
> > been recieved), and opening new sockets upon which to make the "refresh"
> > requests.
> > I think my problem is that completion ports only generate notifications
> for
> > connect/send/recv events, and not for remote socket closure.
> > Most documentation leans towards calling WSAEventSelect(skt, event,
> > FD_CLOSE) for each socket, and then WaitForSingleObject() with an event.
> > Thats fine, but how would i resolve which socket generated the FD_CLOSE
> > event?
> > Thanks for your time,
> > Darren