Skip to content

Commit

Permalink
Use/fix ret_* helpers for certain libc functions
Browse files Browse the repository at this point in the history
- use ret_usize() instead of ret_send_recv() for c::recvmsg(), as it
  always returns c::ssize_t
- use ret_usize() instead of ret_send_recv() for c::sendmsg(), as it
  always returns c::ssize_t
- change the ret_send_recv() used on OSes different than Windows,
  Redox, and wasi to take c::ssize_t as parameter, as it is what
  c::recv(), c::send(), c::recvfrom(), and c::sendto() return on
  most/all of those OSes
  • Loading branch information
pinotree committed Nov 9, 2024
1 parent d51b195 commit 2bcd91a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/backend/libc/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub(super) fn send_recv_len(len: usize) -> i32 {
/// Convert the return value of a `send` or `recv` call.
#[cfg(not(any(windows, target_os = "redox", target_os = "wasi")))]
#[inline]
pub(super) fn ret_send_recv(len: isize) -> io::Result<usize> {
pub(super) fn ret_send_recv(len: c::ssize_t) -> io::Result<usize> {
ret_usize(len)
}

Expand Down
14 changes: 7 additions & 7 deletions src/backend/libc/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::msghdr::with_xdp_msghdr;
#[cfg(target_os = "linux")]
use super::write_sockaddr::encode_sockaddr_xdp;
use crate::backend::c;
use crate::backend::conv::{borrowed_fd, ret, ret_owned_fd, ret_send_recv, send_recv_len};
use crate::backend::conv::{borrowed_fd, ret, ret_owned_fd, ret_usize, ret_send_recv, send_recv_len};
use crate::fd::{BorrowedFd, OwnedFd};
use crate::io;
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -329,7 +329,7 @@ pub(crate) fn recvmsg(

with_recv_msghdr(&mut storage, iov, control, |msghdr| {
let result = unsafe {
ret_send_recv(c::recvmsg(
ret_usize(c::recvmsg(
borrowed_fd(sockfd),
msghdr,
bitflags_bits!(msg_flags),
Expand Down Expand Up @@ -364,7 +364,7 @@ pub(crate) fn sendmsg(
msg_flags: SendFlags,
) -> io::Result<usize> {
with_noaddr_msghdr(iov, control, |msghdr| unsafe {
ret_send_recv(c::sendmsg(
ret_usize(c::sendmsg(
borrowed_fd(sockfd),
&msghdr,
bitflags_bits!(msg_flags),
Expand All @@ -387,7 +387,7 @@ pub(crate) fn sendmsg_v4(
msg_flags: SendFlags,
) -> io::Result<usize> {
with_v4_msghdr(addr, iov, control, |msghdr| unsafe {
ret_send_recv(c::sendmsg(
ret_usize(c::sendmsg(
borrowed_fd(sockfd),
&msghdr,
bitflags_bits!(msg_flags),
Expand All @@ -410,7 +410,7 @@ pub(crate) fn sendmsg_v6(
msg_flags: SendFlags,
) -> io::Result<usize> {
with_v6_msghdr(addr, iov, control, |msghdr| unsafe {
ret_send_recv(c::sendmsg(
ret_usize(c::sendmsg(
borrowed_fd(sockfd),
&msghdr,
bitflags_bits!(msg_flags),
Expand All @@ -430,7 +430,7 @@ pub(crate) fn sendmsg_unix(
msg_flags: SendFlags,
) -> io::Result<usize> {
super::msghdr::with_unix_msghdr(addr, iov, control, |msghdr| unsafe {
ret_send_recv(c::sendmsg(
ret_usize(c::sendmsg(
borrowed_fd(sockfd),
&msghdr,
bitflags_bits!(msg_flags),
Expand All @@ -447,7 +447,7 @@ pub(crate) fn sendmsg_xdp(
msg_flags: SendFlags,
) -> io::Result<usize> {
with_xdp_msghdr(addr, iov, control, |msghdr| unsafe {
ret_send_recv(c::sendmsg(
ret_usize(c::sendmsg(
borrowed_fd(sockfd),
&msghdr,
bitflags_bits!(msg_flags),
Expand Down

0 comments on commit 2bcd91a

Please sign in to comment.