Re: IOCP and closing sockets



On Jul 13, 8:20 pm, David Barrett-Lennard <davi...@xxxxxxxxxxxx>
wrote:
What's an appropriate way to abort socket connections using IOCP under
Windows?  I would prefer not to synchronise access to the socket
handle.  I would have hoped shutdown(SD_BOTH) would abort pending I/O
but it doesn't.   It seems I need to use closesocket(), but that's
going to lead to all sorts of racing conditions.  E.g. the socket
handle could be reused just before the next WSARecv().

1) Set your own internal shutdown flag.

2) Do 'shutdown(SD_BOTH)'.

3) Wait for the number of pending IOCP operations to drop to zero.

4) Notice that your shutdown flag is set and the number of pending
operations is zero, and close the socket.

DS
.



Relevant Pages

  • Re: Overlapped WSASend and IOCP
    ... I actually try to ask about connection closure while some pending IO exists ... on the socket. ... To clean-up per-IO resources we should prematurely initiate ...
    (microsoft.public.win32.programmer.networks)
  • Re: IOCP and closing sockets
    ... Then let pending I/O drain. ... them from making any further calls with the socket handle. ... to the meaningful pending I/O operations on a connected socket (which ...
    (comp.programming.threads)
  • Winsock Pending IO cancellation problem
    ... I am using WinSock & IO Completioned thread pool, ... I want, at a certain point of time, to cancel all pending IO for a certain ... socket, hence, a socket is streaming data to the peer, while doing so, the ...
    (microsoft.public.development.device.drivers)
  • Winsock Pending IO cancellation problem
    ... I am using WinSock & IO Completioned thread pool, ... I want, at a certain point of time, to cancel all pending IO for a certain ... socket, hence, a socket is streaming data to the peer, while doing so, the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: sockets -- basic udp client
    ... print "Received from server: %s" % buf ... default for timeout is no timeout, or block forever, your question: ... a time out on the socket, and you receive no data and the timeout ... of detecting a zero length datagram as transmitted ...
    (comp.lang.python)