Boost logo

Boost Users :

Subject: Re: [Boost-users] [Asio]What's the behavior of socket.async_write() after socket.close() is called?
From: Igor R (boost.lists_at_[hidden])
Date: 2010-05-26 09:18:11


> If I call socket.close() but I still have some data in my buffer, can I call async_write() later?

Obviously, you can't perform i/o on a closed socket.

> When I call socket.close(), maybe an async_write operation is running, when it's complete I want to send data in another
> buffer(data written while previous async_write() is running, before
> socket.close() was called), but the socket is closed.Does it work in this situation?If not, what's the alternative way?

You can't write to a closed socket. Connect the socket again, then
write to it anything you wish.

> void HandleWrite(...)
> {
>   //socket is closed. Does this work?
>   socket.async_write(back_buffer, ...);
> }

No.

> socket.async_write(front_buffer, HandleWrite);
> // write data to back_buffer
> socket.close();

In this case some data might be sent, and some might be not.


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