Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Closing async client socket after writing last message
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-06-23 00:37:25


On 23/06/2014 14:25, Nicholas Yue wrote:
> On 22/06/14 6:58 PM, Gavin Lambert wrote:
>> Do you want something like an actual chat server where connection
>> close can occur at any arbitrary time unrelated to data transmission,
>> or something more like HTTP/FTP where you know in advance that you
>> want to close the connection immediately following a particular transmit?
[...]
> I am after the latter.
>
> Currently, I call a different handler when I am sending the last
> message. That handler does a close. My tests so far indicates that it
> does the close after the last message was sent.

That seems like a reasonable solution to me. (Others include using the
same handler but checking a flag or queue that "knows" when the last
thing has been sent. But using a separate handler will be the fastest
of those.)

Although the notes for close() do mention that it would be safest to
call shutdown() first. Otherwise there is presumably still a chance
that the OS has successfully queued but not actually transmitted the
data, and closing the socket might still cancel it.

> I would like to hear alternative solution as my approach may not be
> technically correct and may have problem during high load.

What sort of problems are you anticipating? (There's no substitute for
testing, of course.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net