Skip to content

Commit e5f7239

Browse files
committed
use BOOL for TCP_NODELAY setsockopt value on Windows
This issue was found by the Wine project and mitigated there [1]. Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY [2]. Windows itself is forgiving and will accept any positive optlen and interpret the first byte of *optval as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's setsockopt, where, e.g., Linux requires that optlen be correct for the chosen option, and TCP_NODELAY expects an int. [1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
1 parent 30b3f35 commit e5f7239

File tree

1 file changed

+2
-2
lines changed
  • library/std/src/sys/windows

1 file changed

+2
-2
lines changed

library/std/src/sys/windows/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ impl Socket {
407407
}
408408

409409
pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> {
410-
net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BYTE)
410+
net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BOOL)
411411
}
412412

413413
pub fn nodelay(&self) -> io::Result<bool> {
414-
let raw: c::BYTE = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?;
414+
let raw: c::BOOL = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?;
415415
Ok(raw != 0)
416416
}
417417

0 commit comments

Comments
 (0)