Skip to content
Commit d6ea38f3 authored by Bastien Orivel's avatar Bastien Orivel Committed by Alexandre Julliard
Browse files

ws2_32: Fix setsockopt(TCP_NODELAY) when optlen is less than 4.

According to MSDN [1], the `TCP_NODELAY` parameter should be of type
`BOOL` which is 4 bytes. Due to a bug [2] in rustc passing a byte
instead of an int, any program written in rust that tries to set that
option on a socket will fail with a "Invalid parameter supplied" error.

Turns out that setsockopt on linux does not want optlen to be less than
4 bytes [3].

Windows' behavior is the following:
- For optlen <= 0, return SOCKET_ERROR and set last error to WSAEFAULT
- For optlen > 0, ignore the optlen value and set the TCP_NODELAY value
  to one if the first byte of the given optvalue is not 0.

This will fix any rust program using the hyper library to do HTTP
requests.

[1]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
[2]: https://github.com/rust-lang/rust/blob/44593aeb1387b1be355aeaf0040d5927bd80f060/library/std/src/sys/windows/net.rs#L470
[3]: https://github.com/torvalds/linux/blob/d58071a8a76d779eedab38033ae4c821c30295a5/net/ipv4/tcp.c#L3419-L3420



Signed-off-by: default avatarBastien Orivel <[email protected]>
Signed-off-by: default avatarZebediah Figura <[email protected]>
Signed-off-by: Alexandre Julliard's avatarAlexandre Julliard <[email protected]>
parent cc91ba6d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment