-
Notifications
You must be signed in to change notification settings - Fork 643
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
Feature: websocket force-close #1122
Comments
There would be useful method that just send close frame and nothing else. Then we can get |
If I correctly understand, |
Hi @vinniefalco, This force call will send the close frame and it will close the socket without waiting for the close frame from the client, right? Right now when we detect that the client has disconnected ungracefully(lost the Internet connection) by using a timer and PING-PONG algorithm, we should call But if we would have this |
"idle ping" and "idle disconnect" timers are now built-in to the websocket stream so you can get rid of all that code and replace it with something like this:
See: https://www.boost.org/doc/libs/master/libs/beast/doc/html/beast/using_websocket/timeouts.html |
Thanks @vinniefalco, I managed to make this change in our code and it works like a charm. There were some issues updating from Older(1.69.0): std::shared_ptr<boost::beast::websocket::stream<
boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>> ws{nullptr} New(1.70.0): std::shared_ptr<boost::beast::websocket::stream<
boost::beast::ssl_stream<boost::beast::tcp_stream>>> ws{nullptr}; Older: const boost::asio::ip::tcp::endpoint& endpoint =
connection->ws->lowest_layer().remote_endpoint(); New: const boost::asio::ip::tcp::endpoint& endpoint =
connection->ws->next_layer().next_layer().socket().remote_endpoint(); I also notice that you cannot create a strand like we did in version std::shared_ptr<boost::beast::websocket::stream<
boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>> ws{nullptr}
std::shared_ptr<boost::asio::strand<boost::asio::io_context::executor_type>> strand{nullptr};
strand = std::make_shared<
boost::asio::strand<boost::asio::io_context::executor_type>>(
ws->get_executor()); We fixed that like you did in the advanced example, we removed the strand variables and used In the advanced example you are using the same We want the Thanks. :D |
You can use
into
Alternatively, you can skip using If you want your acceptor to not use a strand, construct it with the executor returned by I had a look at your code, you will get better results if you pass executors around instead of passing |
Are you referring to this? : socket(::boost::asio::make_strand(ioc))
// or
socket = boost::asio::ip::tcp::socket(boost::asio::make_strand(rw_ioc)); to be replaced with: socket(::boost::asio::make_strand(ioc.get_executor()))
// or
socket = boost::asio::ip::tcp::socket(boost::asio::make_strand(rw_ioc.get_executor())); ? |
No. I mean that you should pass executors around internally. For example:
Instead of storing
And pass instances of these types in interfaces, rather than passing an I/O context. This won't affect performance, it is just a matter of style. However, it does let you easily experiment with changes. Such as using the |
Idle ping/disconnect is a nice feature for lost connections. |
From memory, yes |
This feature can be useful in case of objects destruction. In our situation, we have externa io_conxtext and we can't just stop it. The only possibility is to call async_close and wait for result. Is there any way to close it rapidly in destructor without waiting for async feed back? |
Yes there is a way to close it rapidly, but not from the destructor. You need to cancel the underlying I/O (e.g. using |
So, looks like there is no solution without waiting for callbacks, in both cases, we need to call some function (async_close or lowest_layey-cancel) and wait for handler (on_close or on_read with abortion). Is it correct? |
Another way to do it is to just call
"Waiting for callbacks" implies a long duration, but this is not the case. When you cancel I/O (either by calling |
In some cases it may be useful to have an implementation of
close
andasync_close
which simply sends the close frame at the earliest opportunity and then performs the teardown without waiting for any pending incoming messages to complete.The text was updated successfully, but these errors were encountered: