Re: IOCP with graceful close
- From: "Sam Shi" <sam@xxxxxxxxxxxxx>
- Date: Fri, 19 Aug 2005 15:02:56 +0800
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.
.
- Follow-Ups:
- Re: IOCP with graceful close
- From: Len Holgate
- Re: IOCP with graceful close
- References:
- IOCP with graceful close
- From: Sam Shi
- Re: IOCP with graceful close
- From: Len Holgate
- IOCP with graceful close
- Prev by Date: Re: Network Cable and its performance.
- Next by Date: Re: IOCP with graceful close
- Previous by thread: Re: IOCP with graceful close
- Next by thread: Re: IOCP with graceful close
- Index(es):
Relevant Pages
|
Loading