-
Notifications
You must be signed in to change notification settings - Fork 226
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 request: Non-blocking WebSocket::read
#378
Comments
|
This feature is already there. |
That's great news! But how do I accomplish this? Can I use |
I think I figured it out: match socket.get_mut() {
tungstenite::stream::MaybeTlsStream::Plain(stream) => stream.set_nonblocking(true),
tungstenite::stream::MaybeTlsStream::Rustls(stream) => {
stream.get_mut().set_nonblocking(true)
}
_ => unimplemented!(),
}?; it would be nice if there was a |
Sorry, I meant the underlying |
The |
This still works fine, but an easier path is to set a read timeout But it requires some filtering Err(err) => {
match err {
// Silently drop the error: Processing error: IO error: Resource temporarily unavailable (os error 11)
// That occurs when no messages are to be read
Error::Io(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => Ok(()),
_ => Err(err),
}
}, |
WebSocket::read
is currently blocking. I would love a non-blocking version that tries to read a message, and if there is none, returns immediately.I want to accomplish something like this:
I can accomplish this using
tokio_tungstenite::connect_async
and callingsplit
on the resulting stream, but I rather not pull inasync
andtokio
if I can avoid it!The text was updated successfully, but these errors were encountered: