Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Closing async client socket after writing last message
From: Nicholas Yue (yue.nicholas_at_[hidden])
Date: 2014-06-22 22:25:28

On 22/06/14 6:58 PM, Gavin Lambert wrote:
> On 19/06/2014 06:48, Nicholas Yue wrote:
>> I have adapted the chat tutorial example to send messages to a
>> similar (chat tutorial based) server.
>> It is currently working fine however due to the async_write(), I
>> can't close the socket until after all the pending data has been
>> processed on the server end.
>> I have google and found discussion and mentioned about async_write()
>> completion handler calling socket.close() however, I was not able to
>> find specific detail as to how that is done.
> 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?
> Because these two patterns have different solutions, and the ones
> being discussed in this thread so far are mostly the former while the
> one you mentioned in the last quoted paragraph above is for the latter
> (and is much simpler).
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.

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


Nicholas Yue
Graphics - RenderMan, Visualization, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at