Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_close do not recv peer close frame #2916

Closed
ahao1995 opened this issue Aug 8, 2024 · 5 comments
Closed

async_close do not recv peer close frame #2916

ahao1995 opened this issue Aug 8, 2024 · 5 comments

Comments

@ahao1995
Copy link

ahao1995 commented Aug 8, 2024

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

@ashtum
Copy link
Collaborator

ashtum commented Aug 8, 2024

@ahao1995
Copy link
Author

ahao1995 commented Aug 8, 2024

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?

@ashtum
Copy link
Collaborator

ashtum commented Aug 8, 2024

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

@ahao1995
Copy link
Author

ahao1995 commented Aug 8, 2024

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?

@ashtum
Copy link
Collaborator

ashtum commented Aug 8, 2024

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

@ashtum ashtum closed this as completed Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants