From 8d52695af2c9f6ce87152ef4ae221b2e156ccbce Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Thu, 9 Jul 2026 15:05:47 +0300 Subject: [PATCH] =?UTF-8?q?relibc:=20fix=20disguised=20socket=20stubs=20?= =?UTF-8?q?=E2=80=94=20listen=20+=20setsockopt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed two critical disguised stubs found by comprehensive audit: 1. listen(): updated misleading 'Redox has no need to listen' comment. TCP sockets enter LISTEN state during bind() via smoltcp's tcp_handle.listen(), making POSIX listen() a no-op. The backlog is handled internally via scheme event mechanism. 2. setsockopt(): changed fallthrough from Ok(()) (silent success for unknown socket options) to Err(ENOPROTOOPT). Previously applications calling setsockopt with SO_REUSEADDR, SO_KEEPALIVE, TCP_NODELAY would get success but the option was silently ignored. Now returns the POSIX-correct error for unsupported options. --- src/platform/redox/socket.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index a4b8318eee..c7d325ff8d 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -820,8 +820,14 @@ impl PalSocket for Sys { Err(Errno(ENOSYS)) } - fn listen(socket: c_int, backlog: c_int) -> Result<()> { - // Redox has no need to listen + fn listen(socket: c_int, _backlog: c_int) -> Result<()> { + // TCP sockets enter LISTEN state during bind(), so listen() is + // a no-op on Red Bear. This is a design decision: the kernel's + // netstack (smoltcp) calls tcp_handle.listen() when the socket + // is bound, making the POSIX listen() call redundant. + // The backlog parameter is ignored — Red Bear handles accept + // queuing internally via the scheme event mechanism. + let _ = socket; Ok(()) } @@ -1119,7 +1125,7 @@ impl PalSocket for Sys { option_value, option_len ); - Ok(()) + Err(Errno(ENOPROTOOPT)) } fn shutdown(socket: c_int, how: c_int) -> Result<()> {