Skip to content

Commit

Permalink
Use impl SocketAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Apr 28, 2024
1 parent 17b00ea commit 013792a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/backend/libc/net/msghdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub(crate) fn with_noaddr_msghdr<R>(
}

/// Create a message header intended to send with the specified address.
pub(crate) fn with_msghdr<R, A: SocketAddress>(
addr: &A,
pub(crate) fn with_msghdr<R>(
addr: &impl SocketAddress,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
f: impl FnOnce(c::msghdr) -> R,
Expand Down
12 changes: 6 additions & 6 deletions src/backend/libc/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ pub(crate) unsafe fn recvfrom(
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
pub(crate) fn sendto<A: SocketAddress>(
pub(crate) fn sendto(
fd: BorrowedFd<'_>,
buf: &[u8],
flags: SendFlags,
addr: &A,
addr: &impl SocketAddress,
) -> io::Result<usize> {
unsafe {
addr.with_sockaddr(|addr_ptr, addr_len| {
Expand Down Expand Up @@ -146,7 +146,7 @@ pub(crate) fn socket_with(
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
pub(crate) fn bind<A: SocketAddress>(sockfd: BorrowedFd<'_>, addr: &A) -> io::Result<()> {
pub(crate) fn bind(sockfd: BorrowedFd<'_>, addr: &impl SocketAddress) -> io::Result<()> {
unsafe {
addr.with_sockaddr(|addr_ptr, addr_len| {
ret(c::bind(borrowed_fd(sockfd), addr_ptr, addr_len))
Expand All @@ -155,7 +155,7 @@ pub(crate) fn bind<A: SocketAddress>(sockfd: BorrowedFd<'_>, addr: &A) -> io::Re
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
pub(crate) fn connect<A: SocketAddress>(sockfd: BorrowedFd<'_>, addr: &A) -> io::Result<()> {
pub(crate) fn connect(sockfd: BorrowedFd<'_>, addr: &impl SocketAddress) -> io::Result<()> {
unsafe {
addr.with_sockaddr(|addr_ptr, addr_len| {
ret(c::connect(borrowed_fd(sockfd), addr_ptr, addr_len))
Expand Down Expand Up @@ -256,9 +256,9 @@ pub(crate) fn sendmsg(
target_os = "vita",
target_os = "wasi"
)))]
pub(crate) fn sendmsg_addr<A: SocketAddress>(
pub(crate) fn sendmsg_addr(
sockfd: BorrowedFd<'_>,
addr: &A,
addr: &impl SocketAddress,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
msg_flags: SendFlags,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/linux_raw/net/msghdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub(crate) fn with_noaddr_msghdr<R>(
}

/// Create a message header intended to send with the specified address
pub(crate) fn with_msghdr<R, A: SocketAddress>(
addr: &A,
pub(crate) fn with_msghdr<R>(
addr: &impl SocketAddress,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
f: impl FnOnce(c::msghdr) -> R,
Expand Down
12 changes: 6 additions & 6 deletions src/backend/linux_raw/net/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ pub(crate) fn sendmsg(
}

#[inline]
pub(crate) fn sendmsg_addr<A: SocketAddress>(
pub(crate) fn sendmsg_addr(
sockfd: BorrowedFd<'_>,
addr: &A,
addr: &impl SocketAddress,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
msg_flags: SendFlags,
Expand Down Expand Up @@ -409,11 +409,11 @@ pub(crate) fn send(fd: BorrowedFd<'_>, buf: &[u8], flags: SendFlags) -> io::Resu
}

#[inline]
pub(crate) fn sendto<A: SocketAddress>(
pub(crate) fn sendto(
fd: BorrowedFd<'_>,
buf: &[u8],
flags: SendFlags,
addr: &A,
addr: &impl SocketAddress,
) -> io::Result<usize> {
let (buf_addr, buf_len) = slice(buf);

Expand Down Expand Up @@ -619,7 +619,7 @@ pub(crate) fn getsockname(fd: BorrowedFd<'_>) -> io::Result<SocketAddrAny> {
}

#[inline]
pub(crate) fn bind<A: SocketAddress>(fd: BorrowedFd<'_>, addr: &A) -> io::Result<()> {
pub(crate) fn bind(fd: BorrowedFd<'_>, addr: &impl SocketAddress) -> io::Result<()> {
addr.with_sockaddr(|addr_ptr, addr_len| {
#[cfg(not(target_arch = "x86"))]
unsafe {
Expand All @@ -646,7 +646,7 @@ pub(crate) fn bind<A: SocketAddress>(fd: BorrowedFd<'_>, addr: &A) -> io::Result
}

#[inline]
pub(crate) fn connect<A: SocketAddress>(fd: BorrowedFd<'_>, addr: &A) -> io::Result<()> {
pub(crate) fn connect(fd: BorrowedFd<'_>, addr: &impl SocketAddress) -> io::Result<()> {
addr.with_sockaddr(|addr_ptr, addr_len| {
#[cfg(not(target_arch = "x86"))]
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/net/send_recv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ pub fn recvfrom_uninit<Fd: AsFd>(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendto&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/sendto
/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Sending-Datagrams.html
pub fn sendto<Fd: AsFd, A: SocketAddress>(
pub fn sendto<Fd: AsFd>(
fd: Fd,
buf: &[u8],
flags: SendFlags,
addr: &A,
addr: &impl SocketAddress,
) -> io::Result<usize> {
backend::net::syscalls::sendto(fd.as_fd(), buf, flags, addr)
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/send_recv/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ pub fn sendmsg(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=sendmsg&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/sendmsg
#[inline]
pub fn sendmsg_addr<A: SocketAddress>(
pub fn sendmsg_addr(
socket: impl AsFd,
addr: &A,
addr: &impl SocketAddress,
iov: &[IoSlice<'_>],
control: &mut SendAncillaryBuffer<'_, '_, '_>,
flags: SendFlags,
Expand Down
4 changes: 2 additions & 2 deletions src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn socket_with(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=bind&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/bind
/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Setting-Address.html
pub fn bind<Fd: AsFd, A: SocketAddress>(sockfd: Fd, addr: &A) -> io::Result<()> {
pub fn bind<Fd: AsFd>(sockfd: Fd, addr: &impl SocketAddress) -> io::Result<()> {
backend::net::syscalls::bind(sockfd.as_fd(), addr)
}

Expand Down Expand Up @@ -303,7 +303,7 @@ pub fn bind_xdp<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrXdp) -> io::Result<()> {
/// [illumos]: https://illumos.org/man/3SOCKET/connect
/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Connecting.html
/// [`Errno::WOULDBLOCK`]: io::Errno::WOULDBLOCK
pub fn connect<Fd: AsFd, A: SocketAddress>(sockfd: Fd, addr: &A) -> io::Result<()> {
pub fn connect<Fd: AsFd>(sockfd: Fd, addr: &impl SocketAddress) -> io::Result<()> {
backend::net::syscalls::connect(sockfd.as_fd(), addr)
}

Expand Down

0 comments on commit 013792a

Please sign in to comment.