boostorg/beast

async_close do not recv peer close frame

ahao1995 opened this issue · 5 comments

I use async_close to close the socket, but after 5min recv callback, have any method to force close the connection, and not wait the close frame
may be I should call

std::optional<boost::beast::websocket::stream<
    boost::beast::ssl_stream<boost::beast::tcp_stream>>> ws_stream_;
//force close?
boost::beast::get_lowest_layer(*ws_stream_).cancel();

after that I want to do reconnect

ws_stream_.emplace(exec_, ctx_);

it is right?
thanks

Have you set a timeout on the stream? https://www.boost.org/doc/libs/1_85_0/libs/beast/doc/html/beast/using_websocket/timeouts.html

I do not use timeout, I want to close it quickly and reconnect, just like force close not graceful, is there some method?

beast::get_lowest_layer(*ws_stream_).close(); will do it, or you can simply ignore the stream object and let it be destroyed.

beast::get_lowest_layer(*ws_stream_).close(); will do it, or you can simply ignore the stream object and let it be destroyed.

you mean direct use ws_stream_.emplace(exec_, ctx_); let it destroy?

Yes, that would have the same effect as closing the underlying socket.