Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Closing async client socket after writing last message
From: Bjorn Reese (breese_at_[hidden])
Date: 2014-06-19 07:02:39


On 06/18/2014 10:49 PM, Nicholas Yue wrote:

> Does that mean that the examples will example this problem ?
>
> http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp03/chat/chat_client.cpp
>
> as it does a pop before checking

Sorry, I read the code too quickly.

So if I understand your question correctly, the chat example will
discard queued messages on a close, whereas you want the close to be
deferred until the queue is empty?

One way to achieve this is to change do_close() to check the queue. If
empty, close the socket, and if not then set a want_to_close flag. Then
change handle_write() to check the want_to_close flag if the queue is
empty, and call do_close().


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