Skip to content

Commit 1b5fc34

Browse files
committed
finish test
1 parent 83c00d1 commit 1b5fc34

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

library/std/src/os/windows/net/listener.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ use crate::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket, RawSocke
99
use crate::os::windows::net::{SocketAddr, UnixStream, from_sockaddr_un};
1010
use crate::path::Path;
1111
use crate::sys::c::{self, bind, getsockname, listen};
12-
use crate::sys::cvt;
1312
use crate::sys::net::Socket;
14-
13+
use crate::sys::winsock::startup;
1514
pub struct UnixListener(Socket);
1615

1716
impl UnixListener {
1817
pub fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
1918
unsafe {
19+
startup();
2020
let inner = Socket::new_unix()?;
2121
let (addr, len) = sockaddr_un(path.as_ref())?;
22-
cvt(bind(inner.as_raw(), &addr as *const _ as *const _, len))?;
23-
cvt(listen(inner.as_raw(), 128))?;
22+
if bind(inner.as_raw(), &addr as *const _ as *const _, len) != 0 {
23+
panic!("err: {}", io::Error::last_os_error())
24+
}
25+
if listen(inner.as_raw(), 128) != 0 {
26+
panic!("err: {}", io::Error::last_os_error())
27+
}
2428
Ok(UnixListener(inner))
2529
}
2630
}

library/std/src/os/windows/net/stream.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ use crate::os::windows::io::{
1111
use crate::os::windows::net::{SocketAddr, sockaddr_un};
1212
use crate::path::Path;
1313
use crate::sys::c::{SO_RCVTIMEO, SO_SNDTIMEO, connect, getpeername, getsockname};
14-
use crate::sys::cvt;
1514
use crate::sys::net::Socket;
16-
15+
use crate::sys::winsock::startup;
1716
pub struct UnixStream(pub Socket);
1817
impl UnixStream {
1918
pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
2019
unsafe {
20+
startup();
2121
let inner = Socket::new_unix()?;
2222
let (addr, len) = sockaddr_un(path.as_ref())?;
23-
cvt(connect(inner.as_raw() as _, &addr as *const _ as *const _, len))?;
23+
if connect(inner.as_raw() as _, &addr as *const _ as *const _, len) != 0 {
24+
panic!("err: {}", io::Error::last_os_error())
25+
}
2426
Ok(UnixStream(inner))
2527
}
2628
}

library/std/tests/windows_unix_socket.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use std::thread;
99
fn smoke_bind_connect() {
1010
let tmp = std::env::temp_dir();
1111
let sock_path = tmp.join("rust-test-uds.sock");
12+
let _ = std::fs::remove_file(&sock_path);
1213
let listener = UnixListener::bind(&sock_path).expect("bind failed");
13-
let sock_path_clone = sock_path.clone();
14+
let sock_path_clone = sock_path.clone();
1415
let tx = thread::spawn(move || {
1516
let mut stream = UnixStream::connect(&sock_path_clone).expect("connect failed");
1617
stream.write_all(b"hello").expect("write failed");

0 commit comments

Comments
 (0)