Re: Pending WSARecv do not return when closesocket() is called



As a wild guess, try setting SO_UPDATE_ACCEPT_CONTEXT

See the AcceptEx documentation at
http://msdn2.microsoft.com/en-us/library/ms737524.aspx , about halfway down.

Incidentally, does closesocket() return SOCKET_ERROR? And if so what does
WSAGetLastError show?


<nibiru.meister@xxxxxxxxx> wrote in message
news:1172078570.999915.154820@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello everyone,

I have a mysterious problem with IOCP.
I wrote a simple telnet server which basically accepts connections and
on a successful connection start "cmd.exe" with I/O redirectoin so
that input from the client socket gets redirected to the input of
cmd.exe and the output of cmd.exe is sent back to the client socket.
The input/output to cmd.exe is done through a named pipe (I start
cmd.exe with I/O redirection).
All of this is done through 1 IOCP (socket send/read and named pipe
write/read).

Everything worked well when I was using synchronous accept, but then i
wanted to use AcceptEx so that everything will be asynchrnous, and
here i encountred a problem i'm not sure how to solve.

The asynch AcceptEx works ok, clients get connected and work alright,
the problem is when a client wants to disconnect. A client disconnects
normally by pressesing 'exit' which makes cmd.exe terminate which in
turn closes the named pipe it was using.
The pending read on that pipe returns with a failure and realizing the
pipe has ended it does a closesocket() on the socket received from
AcceptEx().

And the problem: The closesocket() doesn't fail the pending read on
the socket!!
The read operation continues to wait as if the socket handle hasn't
been closed.

I have checked everything i could, tried SO_LINGER with {0,0} , tried
shutdown() on the socket before closesocket(), double checked I am
doing a closesocket() on the right socket, and nothing makes the
pending read operation return (fail) when closesocket() is called on a
socket I received from AcceptEx().

Anyone have any idea what can cause this behaviour?

Thanks a lot.



.



Relevant Pages

  • Re: Problem receiving Multicast traffic transmitted on receiving inter
    ... when using a separate receiver socket, ... I have a service that both sends and receives multicast frames. ... closesocket; ... sizeof ) == SOCKET_ERROR) ...
    (microsoft.public.windowsce.embedded)
  • Pending WSARecv do not return when closesocket() is called
    ... cmd.exe and the output of cmd.exe is sent back to the client socket. ... All of this is done through 1 IOCP (socket send/read and named pipe ... The closesocket() doesn't fail the pending read on ...
    (microsoft.public.win32.programmer.networks)
  • Re: socket question: how to use sendto and recvfrom based on the same multicast address
    ... Why don't you just use the same socket for both send and receive? ... multicast address and receive other data from others on the samd ... closesocket; ... if (setsockopt (sockrcv, ...
    (microsoft.public.windowsce.platbuilder)
  • Re: IOCP with graceful close
    ... server send a Command to client and then closesocket. ... the client can't always receive the cmd before the socket is closed. ... However you probably really want the client to initiate the connection closure as it's the side that performs the 'active close' that goes into TIME_WAIT and it's best not to 'collect' TIME_WAIT sockets on your server side... ... The server has an outstanding recv on the socket and this now completes and returns 0 to indicated that the client has closed the connection. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Need Help with IOCP
    ... about "the client only gets partially notified of the socket close"? ... , not related with socket closure. ... - To completely close your connection with your ... > - using a worker thread to sleepand closesocket ...
    (microsoft.public.win32.programmer.networks)