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
.