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/client/mod.rs | |
| parent | 52e57507e10ee7cb2869156fb1f00e280e614736 (diff) | |
fix: preserve unix socket error semantics
Diffstat (limited to 'src/client/mod.rs')
| -rw-r--r-- | src/client/mod.rs | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs index a895dae0..8236bb44 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -448,6 +448,33 @@ fn requested_keybindings() -> ClientKeybindings { } } +#[cfg(windows)] +fn set_handshake_recv_timeout( + stream: &LocalStream, + timeout: Option<Duration>, + context: &'static str, +) -> Result<(), ClientError> { + match stream.set_recv_timeout(timeout) { + Ok(()) => Ok(()), + Err(err) if err.kind() == io::ErrorKind::Unsupported => { + debug!(err = %err, context, "client socket receive timeout unavailable"); + Ok(()) + } + Err(err) => Err(ClientError::ConnectionFailed(err)), + } +} + +#[cfg(not(windows))] +fn set_handshake_recv_timeout( + stream: &LocalStream, + timeout: Option<Duration>, + _context: &'static str, +) -> Result<(), ClientError> { + stream + .set_recv_timeout(timeout) + .map_err(ClientError::ConnectionFailed) +} + /// Performs the client→server handshake. /// /// Sends Hello with the terminal size and protocol version, reads the Welcome @@ -484,13 +511,17 @@ fn do_handshake( .map_err(|e| ClientError::ConnectionFailed(io::Error::other(e.to_string())))?; // Read Welcome. - if let Err(err) = stream.set_recv_timeout(Some(Duration::from_secs(5))) { - debug!(err = %err, "client handshake read timeout unavailable"); - } + set_handshake_recv_timeout( + stream, + Some(Duration::from_secs(5)), + "client handshake read timeout unavailable", + )?; let welcome: ServerMessage = protocol::read_message(stream, MAX_FRAME_SIZE)?; - if let Err(err) = stream.set_recv_timeout(None) { - debug!(err = %err, "failed to clear client handshake read timeout"); - } + set_handshake_recv_timeout( + stream, + None, + "failed to clear client handshake read timeout", + )?; match welcome { ServerMessage::Welcome { |
