Repository: rustfs/rustfs
File: rustfs/src/server/http.rs (Rust)

Code before:
            let socket_ref = SockRef::from(&socket);

            // Enable TCP Keepalive to detect dead clients (e.g. power loss)
            // Idle: 10s, Interval: 5s, Retries: 3
            #[cfg(target_os = "openbsd")]
            let ka = TcpKeepalive::new().with_time(Duration::from_secs(10));

            #[cfg(not(target_os = "openbsd"))]
            let ka = TcpKeepalive::new()
                .with_time(Duration::from_secs(10))
                .with_interval(Duration::from_secs(5))
                .with_retries(3);

            if let Err(err) = socket_ref.set_tcp_keepalive(&ka) {
                warn!(?err, "Failed to set TCP_KEEPALIVE");
            }

            if let Err(err) = socket_ref.set_tcp_nodelay(true) {
                warn!(?err, "Failed to set TCP_NODELAY");
            }

            #[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
            if let Err(err) = socket_ref.set_recv_buffer_size(4 * MI_B) {
                warn!(?err, "Failed to set set_recv_buffer_size");
            }
            #[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
            if let Err(err) = socket_ref.set_send_buffer_size(4 * MI_B) {
                warn!(?err, "Failed to set set_send_buffer_size");
            }

            let connection_ctx = ConnectionContext {
                http_server: http_server.clone(),
                s3_service: s3_service.clone(),
                cors_layer: cors_layer.clone(),
                compression_config: compression_config.clone(),
                is_console,
                readiness: readiness.clone(),
            };

            process_connection(socket, tls_acceptor.clone(), connection_ctx, graceful.clone());
        }

        worker_state_manager.update(ServiceState::Stopping);
        match Arc::try_unwrap(graceful) {
            Ok(g) => {
                tokio::select! {
                    () = g.shutdown() => {
                        debug!("Gracefully shutdown!");
                    },
                    () = tokio::time::sleep(Duration::from_secs(10)) => {
                        debug!("Waited 10 seconds for graceful shutdown, aborting...");

Review comment (suggestion):
`netbsd` not support ？

https://github.com/rust-lang/socket2/blob/3403a440e57101f3c98995b7ef7c8de74fbff14d/src/socket.rs#L1145

Code after:
            // Idle: 10s, Interval: 5s, Retries: 3
            #[cfg(target_os = "openbsd")]
            let ka = TcpKeepalive::new().with_time(Duration::from_secs(10));

            #[cfg(not(target_os = "openbsd"))]
            let ka = TcpKeepalive::new()
                .with_time(Duration::from_secs(10))
                .with_interval(Duration::from_secs(5))
                .with_retries(3);

            if let Err(err) = socket_ref.set_tcp_keepalive(&ka) {
                warn!(?err, "Failed to set TCP_KEEPALIVE");
            }

            if let Err(err) = socket_ref.set_tcp_nodelay(true) {
                warn!(?err, "Failed to set TCP_NODELAY");
            }

            #[cfg(not(target_os = "openbsd"))]
            if let Err(err) = socket_ref.set_recv_buffer_size(4 * rustfs_config::MI_B) {
                warn!(?err, "Failed to set set_recv_buffer_size");
            }
            #[cfg(not(target_os = "openbsd"))]
            if let Err(err) = socket_ref.set_send_buffer_size(4 * rustfs_config::MI_B) {
                warn!(?err, "Failed to set set_send_buffer_size");
            }

            let connection_ctx = ConnectionContext {
                http_server: http_server.clone(),
                s3_service: s3_service.clone(),
                cors_layer: cors_layer.clone(),
                compression_config: compression_config.clone(),
                is_console,
                readiness: readiness.clone(),
            };

            process_connection(socket, tls_acceptor.clone(), connection_ctx, graceful.clone());
        }

        worker_state_manager.update(ServiceState::Stopping);
        match Arc::try_unwrap(graceful) {
            Ok(g) => {
                tokio::select! {
                    () = g.shutdown() => {
                        debug!("Gracefully shutdown!");
                    },
                    () = tokio::time::sleep(Duration::from_secs(10)) => {
                        debug!("Waited 10 seconds for graceful shutdown, aborting...");
                    }
                }
            }