-
The following program makes an attempt to connect to 0.0.0.0:8080 using both io_uring and plain old libc. I expect the returned values to be identical. However, they are not. In case of io_uring the returned value is -111. In case of libc it is -1 (as it should be according to documentation). I would like to get an explanation of that behaviour. fn main() {
libc_connect(); io_uring_connect();
}
const ADDR: libc::sockaddr_in = libc::sockaddr_in {
sin_family: libc::AF_INET as libc::sa_family_t,
sin_addr: libc::in_addr { s_addr: u32::from_ne_bytes([0, 0, 0, 0]) },
sin_port: 8080,
sin_zero: [0; 8]
};
fn libc_connect() {
unsafe {
let socket = libc::socket(libc::AF_INET, libc::SOCK_STREAM | libc::SOCK_CLOEXEC, 0);
println!("libc connect: {}", libc::connect(socket, &ADDR as *const _ as *const libc::sockaddr, std::mem::size_of::<libc::sockaddr_in>() as libc::socklen_t));
libc::close(socket);
}
}
fn io_uring_connect() {
use io_uring::IoUring;
use io_uring::opcode::Connect;
use io_uring::types::Fd;
unsafe {
let mut io_uring = IoUring::new(2).unwrap();
let socket = libc::socket(libc::AF_INET, libc::SOCK_STREAM | libc::SOCK_CLOEXEC, 0);
io_uring.submission()
.push(&Connect::new(Fd(socket), &ADDR as *const _ as *const libc::sockaddr, std::mem::size_of::<libc::sockaddr_in>() as libc::socklen_t).build())
.unwrap();
io_uring.submit_and_wait(1).unwrap();
println!("io_uring connect: {}", io_uring.completion().next().unwrap().result());
libc::close(socket);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
from man connect(2): You should look at errno to get the actual error code. io_uring just returns the error code in the completion (I assume - I have not run this rust code) |
Beta Was this translation helpful? Give feedback.
-
You're kidding, right? It's literally even in the io_uring_prep_connect(3) man page. You just didn't read the documentation. |
Beta Was this translation helpful? Give feedback.
from man connect(2):
If the connection or binding succeeds, zero is returned. On
error, -1 is returned, and errno is set to indicate the error.
You should look at errno to get the actual error code.
io_uring just returns the error code in the completion
(I assume - I have not run this rust code)