Skip to content

Commit

Permalink
wip changes to fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML committed Sep 20, 2023
1 parent 48db06f commit 149095f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::socket_addr;
use super::SocketAddr;
use crate::net::UnixStream;
use crate::net::{SocketAddr, UnixStream};
use crate::sys::unix::net::new_socket;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::{AsRawFd, FromRawFd};
Expand Down
10 changes: 9 additions & 1 deletion src/sys/windows/stdnet/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cfg_os_poll! {
}

/// An address associated with a Unix socket.
pub struct SocketAddr {
pub(crate) struct SocketAddr {
addr: SOCKADDR_UN,
len: c_int,
}
Expand Down Expand Up @@ -121,6 +121,14 @@ impl SocketAddr {
len,
})
}

pub(crate) fn raw_sockaddr(&self) -> &SOCKADDR_UN {
&self.addr
}

pub(crate) fn raw_socklen(&self) -> c_int {
self.len
}
}

/// Returns the contents of this address if it is a `pathname` address.
Expand Down
14 changes: 14 additions & 0 deletions src/sys/windows/stdnet/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ cfg_os_poll! {
})
}

/// Creates a new `UnixListener` bound to the specified address.
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
let inner = Socket::new()?;

wsa_syscall!(
bind(inner.as_raw_socket() as _, &socket_addr.raw_sockaddr() as *const _ as *const _, socket_addr.raw_socklen() as _),
SOCKET_ERROR
)?;
wsa_syscall!(listen(inner.as_raw_socket() as _, 1024), SOCKET_ERROR)?;
Ok(UnixListener {
inner
})
}

/// Accepts a new incoming connection to this listener.
///
/// This function will block the calling thread until a new Unix connection
Expand Down
2 changes: 1 addition & 1 deletion src/sys/windows/stdnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod listener;
mod socket;
mod stream;

pub use self::addr::SocketAddr;
pub(crate) use self::addr::SocketAddr;
pub use self::listener::UnixListener;
pub use self::stream::UnixStream;

Expand Down
19 changes: 19 additions & 0 deletions src/sys/windows/stdnet/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ cfg_os_poll! {
Ok(UnixStream(inner))
}

/// Connects to the socket named by `socker_addr`.
pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result<UnixStream> {
let inner = Socket::new()?;

match wsa_syscall!(
connect(
inner.as_raw_socket() as _,
&socket_addr.raw_sockaddr() as *const _ as *const _,
socket_addr.raw_socklen(),
),
SOCKET_ERROR
) {
Ok(_) => {}
Err(ref err) if err.kind() == std::io::ErrorKind::Other => {}
Err(e) => return Err(e),
}
Ok(UnixStream(inner))
}

/// Moves the socket into or out of nonblocking mode.
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
self.0.set_nonblocking(nonblocking)
Expand Down
9 changes: 7 additions & 2 deletions src/sys/windows/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::io;
use std::os::windows::io::AsRawSocket;
use std::path::Path;

use super::SocketAddr;
use crate::net::UnixStream;
use crate::net::{SocketAddr, UnixStream};
use crate::sys::windows::stdnet as net;

pub(crate) fn bind(path: &Path) -> io::Result<net::UnixListener> {
Expand All @@ -12,6 +11,12 @@ pub(crate) fn bind(path: &Path) -> io::Result<net::UnixListener> {
Ok(listener)
}

pub(crate) fn bind_addr(socket_addr: &SocketAddr) -> io::Result<net::UnixListener> {
let listener = net::UnixListener::bind_addr(socket_addr)?;
listener.set_nonblocking(true)?;
Ok(listener)
}

pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, SocketAddr)> {
listener.set_nonblocking(true)?;
let (stream, addr) = listener.accept()?;
Expand Down
6 changes: 6 additions & 0 deletions src/sys/windows/uds/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub(crate) fn connect(path: &Path) -> io::Result<net::UnixStream> {
Ok(socket)
}

pub(crate) fn connect_addr(socker_addr: &SocketAddr) -> io::Result<net::UnixStream> {
let socket = net::UnixStream::connect_addr(socker_addr)?;
socket.set_nonblocking(true)?;
Ok(socket)
}

pub(crate) fn local_addr(socket: &net::UnixStream) -> io::Result<SocketAddr> {
super::local_addr(socket.as_raw_socket())
}
Expand Down

0 comments on commit 149095f

Please sign in to comment.