You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to implement "idle timeout" logic with websockets where it times out when there has been no read activity for a certain number of seconds.
With Asio TCP sockets, I would simply use tcpsocket.async_wait(asio::ip::tcp::socket::wait_read, handler), followed by async_read with the timing logic in between. See Asio's async_wait docs here.
But there is no equivalent beast::websocket::stream::async_wait method.
As as workaround, is it safe to call websocket.next_layer().async_wait(asio::ip::tcp::socket::wait_read, handler) before calling websocket.async_read(...) ?
The text was updated successfully, but these errors were encountered:
But I'd still like to know if next_layer().async_wait(...) is safe before calling async_read on a websocket stream.
Nope, just tried it and it broke things. Was probably a bad idea anyway to manipulate the next_layer() socket while it was under websocket::stream's ownership.
Another workaround just came to mind: I can just do websocket.async_read_some(...) with a limit of a single byte.
This works. Closing this issue as I ended up answering my own questions, but feel free to re-open if you think websocket::stream deserves an async_read member function similar to asio::ip::tcp:stream.
Version of Beast: Boost 1.83
I need to implement "idle timeout" logic with websockets where it times out when there has been no read activity for a certain number of seconds.
With Asio TCP sockets, I would simply use
tcpsocket.async_wait(asio::ip::tcp::socket::wait_read, handler)
, followed byasync_read
with the timing logic in between. See Asio's async_wait docs here.But there is no equivalent
beast::websocket::stream::async_wait
method.As as workaround, is it safe to call
websocket.next_layer().async_wait(asio::ip::tcp::socket::wait_read, handler)
before callingwebsocket.async_read(...)
?The text was updated successfully, but these errors were encountered: