How to check for HUPs on a TlsStream split with tokio::io::split? #5419
-
I'm writing a TLS client that reads and writes to a split TlsStream (ReadHalf / WriteHalf). Sometimes, the upstream server shutsdown or resets (probably SO_LINGER of zero) the stream. I need a way to reliably detect this on my client, as when I write to the WriteHalf, it succeeds, even though the connection is already reset, which 'loses' the write. If I do not split the stream, I can check for resets with what feels like a hack: if let Ok(ready_status) = tls_stream.get_ref().0.ready(tokio::io::Interest::READABLE | tokio::io::Interest::WRITABLE).await {
if !ready_status.is_read_closed() && !ready_status.is_write_closed() {
if let Ok(_bytes_written_to_socket) = tokio::io::AsyncWriteExt::write(&mut write_tls_stream, &query_buf).await {
<some unrelated code here>
}
}
} However, I do not have access to the underlying TcpStream after I split the TlsStream, so I can't do the above 'hack'. My overall goal is to support full duplex TlsStream reads and writes in separate Tasks, where, if a HUP is detected, the connection is re-established before any further reads / writes occur. Any ideas on how I can go about solving this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Looks like the answer was just to check the result of the flush: tokio::io::AsyncWriteExt::flush(&mut write_half) |
Beta Was this translation helpful? Give feedback.
Looks like the answer was just to check the result of the flush: