Re: IOCP and closing sockets



On Jul 25, 10:58 am, "Chris M. Thomasson" <cris...@xxxxxxxxxxx> wrote:
"David Barrett-Lennard" <davi...@xxxxxxxxxxxx> wrote in message

news:733c4aeb-3fad-4c92-b4e4-111b84642c04@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx





On Jul 24, 2:16 pm, "Chris M. Thomasson" <cris...@xxxxxxxxxxx> wrote:
"David Schwartz" <dav...@xxxxxxxxxxxxx> wrote in message

news:66aa7c5a-16af-41cb-9906-38c90e4ebfd6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 18, 12:43 am, "Chris M. Thomasson" <cris...@xxxxxxxxxxx> wrote:

Using `closesocket()' and hashed locking scheme.to per-socket state
is
usually just fine. Simply set a flag indicating that `closesocket()'
has
been called. Then let pending I/O drain. When the "cancelled"
completions
come in they will notice that the flag has been set, which should
prevent
them from making any further calls with the socket handle.
The problem is that you cannot open or accept any new sockets during
this time window. That seems to be an awfully high price to pay.

Yikes. I meant to say `DisconnectEx()' instead of `closesocket()'! Also,
it's dangerous to call `closesocket()' when there is a pending
`AcceptEx()/ConnextEx()' call. IIRC, it might cause a memory leak.

Also, IIRC, `DisconnectEx()' can be safely used to close a socket while
it
has pending I/O operations... According to:

http://www.microsoft.com/mspress/books/sampchap/5726.aspx#SampleChapter

I don't see where it suggests DisconnectEx can be used to abort a
pending AcceptEx/ConnectEx. It appears to me that both the ch6 of
Network Programming you referenced and the MSDN documentation on
DisconnectEx imply the function is (only) intended to be used on a
connected socket.

It basically says that `DisconnectEx()' will return `WSA_IO_PENDING' if the
socket has pending overlapped I/O operations. AFAICT, pending
`AcceptEx()/ConnectEx()' count as pending overlapped I/O ops.

I had thought in that context "pending I/O operations" only referred
to the meaningful pending I/O operations on a connected socket (which
are reads and writes).

The precondition on DisconnectEx that the given socket handle is
already connected is explicit in MSDN:

http://msdn.microsoft.com/en-us/library/ms737757(v=vs.85).aspx

states:

"The DisconnectEx function closes a connection on a socket, and
allows the socket handle to be reused",

and the parameter hSocket is described as:

"A handle to a connected, connection-oriented socket"

.



Relevant Pages

  • Re: IOCP and closing sockets
    ... Simply set a flag indicating that `closesocket' ... Then let pending I/O drain. ... Also, IIRC, `DisconnectEx' can be safely used to close a socket while ...
    (comp.programming.threads)
  • 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)
  • 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)
  • 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)
  • Re: IOCP and closing sockets
    ...  I would prefer not to synchronise access to the socket ... Wait for the number of pending IOCP operations to drop to zero. ...
    (comp.programming.threads)