Closed jothan closed 1 month ago
I think I found the bug.
LWIP defines TCP_NODELAY as 1 in esp-idf/components/lwip/lwip/src/include/lwip/sockets.h:
#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
While Rust uses the libc::TCP_NODELAY with a value of 8193 defined by the libc crate in src/unix/newlib/mod.rs:
cfg_if! {
if #[cfg(target_os = "vita")] {
pub const TCP_NODELAY: ::c_int = 1;
pub const TCP_MAXSEG: ::c_int = 2;
} else {
pub const TCP_NODELAY: ::c_int = 8193;
pub const TCP_MAXSEG: ::c_int = 8194;
}
}
I found this pull request that would fix this issue on the libc crate repository: https://github.com/rust-lang/libc/pull/3345
I've hit the same, for now I've done this as a workaround
extern "C" {
fn lwip_setsockopt(fd: i32, level: i32, optname: i32);
}
unsafe {
lwip_setsockopt(
conn.as_raw_fd(),
6, // tcp https://github.com/stm32duino/LwIP/blob/main/src/lwip/sockets.h#L250
1, // nodelay https://github.com/stm32duino/LwIP/blob/main/src/lwip/sockets.h#L279
)
};
Closed via https://github.com/rust-lang/libc/pull/3920
I tried this code:
I expected to see this happen: the socket should have been put in nodelay mode without issue.
Instead, this happened:
The TCP_NODELAY option should be supported: https://docs.espressif.com/projects/esp-idf/en/v5.2.1/esp32/api-guides/lwip.html#tcp-options
Meta
rustc --version --verbose
: