Re: IOCP with graceful close



I tried to shutdown(SD_SEND) after I sent the last data. But I find the
socket is shutdown before the the send data is arrive to send queue of IOCP.
maybe shutdown is not a good method to process IOCP.


"Len Holgate" <Len.Holgate@xxxxxxxxxxx>
:43031318$0$12901$cc9e4d1f@xxxxxxxxxxxxxxxxxxxxxx
>> My server side uses IOCP model. When some condition is meet, I want to
>> server send a Command to client and then closesocket. If I use
>> non-graceful close, the client can't always receive the cmd before the
>> socket is closed.
>
> You should be able to call shutdown(SD_BOTH), set linger and then
> closesocket. 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... So, I'd suggest the following; Send your last command
> and call shutdown(SD_SEND) to tell the client that you wont send any more
> data. The client gets the last command and acts on it, the next read the
> client issues returns 0 indicating that the server has shut down the send
> side. The client calls shutdown(SD_BOTH) and closesocket - no need to
> linger as there's no data on the wire. 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. The server calls closesocket and the
> connection is closed.
>
> This should leave a socket in TIME_WAIT on the client and nothing on the
> server.
>
> Our IOCP server framework is a little more complicated than that as we use
> write completion notifications to control when a send shutdown actually
> happens, see the code on my blog if you're interested.
>
> --
> Len Holgate - http://www.lenholgate.com
> JetByte Limited - http://www.jetbyte.com
> The right code, right now.
> Contract Programming and Consulting Services.


.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)

Loading