diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-07 02:03:39 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-07 16:29:45 +0300 |
| commit | f61ed48eff622de4f970adff220603ea50292f07 (patch) | |
| tree | 1d7028b60a137e6f2e67c3c5435788a11b974344 /src/server | |
| parent | 52e57507e10ee7cb2869156fb1f00e280e614736 (diff) | |
fix: preserve unix socket error semantics
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/client_transport.rs | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/server/client_transport.rs b/src/server/client_transport.rs index 4bbf7bbf..b7e19bb3 100644 --- a/src/server/client_transport.rs +++ b/src/server/client_transport.rs @@ -153,6 +153,33 @@ fn input_events_within_limits(events: &[ClientInputEvent]) -> bool { true } +#[cfg(windows)] +fn set_client_recv_timeout( + stream: &LocalStream, + timeout: Option<Duration>, + context: &'static str, + client_id: u64, +) -> io::Result<()> { + match stream.set_recv_timeout(timeout) { + Ok(()) => Ok(()), + Err(err) if err.kind() == io::ErrorKind::Unsupported => { + debug!(client_id, err = %err, context, "client socket receive timeout unavailable"); + Ok(()) + } + Err(err) => Err(err), + } +} + +#[cfg(not(windows))] +fn set_client_recv_timeout( + stream: &LocalStream, + timeout: Option<Duration>, + _context: &'static str, + _client_id: u64, +) -> io::Result<()> { + stream.set_recv_timeout(timeout) +} + /// Handles the client handshake on a blocking thread. /// /// Reads the `Hello` message, validates the version, sends `Welcome`, @@ -167,9 +194,12 @@ pub(crate) fn handle_client_handshake( // the handshake thread needs blocking I/O for read_message/write_message. stream.set_nonblocking(false)?; - if let Err(err) = stream.set_recv_timeout(Some(HANDSHAKE_TIMEOUT)) { - debug!(client_id, err = %err, "client handshake read timeout unavailable"); - } + set_client_recv_timeout( + &stream, + Some(HANDSHAKE_TIMEOUT), + "client handshake read timeout unavailable", + client_id, + )?; // Read the Hello message. let hello: ClientMessage = match protocol::read_message(&mut stream, MAX_FRAME_SIZE) { @@ -268,9 +298,12 @@ pub(crate) fn handle_client_handshake( }; protocol::write_message(&mut stream, &welcome).map_err(|e| io::Error::other(e.to_string()))?; - if let Err(err) = stream.set_recv_timeout(None) { - debug!(client_id, err = %err, "failed to clear client handshake read timeout"); - } + set_client_recv_timeout( + &stream, + None, + "failed to clear client handshake read timeout", + client_id, + )?; // Create separate channels for reliable control messages and droppable renders. let (control_tx, control_rx) = std::sync::mpsc::channel::<Vec<u8>>(); |
