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

No websocket::stream::async_wait method #2773

Closed
ecorm opened this issue Dec 2, 2023 · 3 comments
Closed

No websocket::stream::async_wait method #2773

ecorm opened this issue Dec 2, 2023 · 3 comments

Comments

@ecorm
Copy link

ecorm commented Dec 2, 2023

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 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(...) ?

@ecorm
Copy link
Author

ecorm commented Dec 2, 2023

Another workaround just came to mind: I can just do websocket.async_read_some(...) with a limit of a single byte.

But I'd still like to know if next_layer().async_wait(...) is safe before calling async_read on a websocket stream.

@ecorm
Copy link
Author

ecorm commented Dec 2, 2023

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.

@ecorm
Copy link
Author

ecorm commented Dec 2, 2023

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.

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

1 participant