Skip to content

Commit 9ecb819

Browse files
committed
stream
1 parent 1a2ec2a commit 9ecb819

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem;
33
use super::sockaddr_un;
44
use crate::io;
55
use crate::os::raw::c_int;
6-
use crate::os::windows::net::{SocketAddr, from_sockaddr_un};
6+
use crate::os::windows::net::{SocketAddr, UnixStream, from_sockaddr_un};
77
use crate::path::Path;
88
use crate::sys::c::{self, bind, getsockname, listen};
99
use crate::sys::cvt;
@@ -13,7 +13,6 @@ use crate::sys::net::Socket;
1313
pub struct UnixListener(Socket);
1414
#[stable(feature = "rust1", since = "1.0.0")]
1515

16-
pub struct UnixStream(Socket);
1716
impl UnixListener {
1817
#[stable(feature = "rust1", since = "1.0.0")]
1918
pub fn bind<P: AsRef<Path>>(path: &Path) -> io::Result<UnixListener> {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
mod addr;
44
mod listener;
5+
mod stream;
56
#[stable(feature = "rust1", since = "1.0.0")]
67
pub use addr::*;
78
#[stable(feature = "rust1", since = "1.0.0")]
89
pub use listener::*;
10+
#[stable(feature = "rust1", since = "1.0.0")]
11+
pub use stream::*;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#![stable(feature = "rust1", since = "1.0.0")]
2+
3+
use core::time::Duration;
4+
5+
use crate::io;
6+
use crate::net::Shutdown;
7+
use crate::os::windows::net::{SocketAddr, sockaddr_un};
8+
use crate::path::Path;
9+
use crate::sys::c::{SO_RCVTIMEO, SO_SNDTIMEO, connect, getpeername, getsockname};
10+
use crate::sys::cvt;
11+
use crate::sys::net::Socket;
12+
13+
#[stable(feature = "rust1", since = "1.0.0")]
14+
pub struct UnixStream(pub Socket);
15+
impl UnixStream {
16+
#[stable(feature = "rust1", since = "1.0.0")]
17+
pub fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
18+
unsafe {
19+
let inner = Socket::new_unix()?;
20+
let (addr, len) = sockaddr_un(path.as_ref())?;
21+
cvt(connect(inner.as_raw() as _, &addr as *const _ as *const _, len))?;
22+
Ok(UnixStream(inner))
23+
}
24+
}
25+
#[stable(feature = "rust1", since = "1.0.0")]
26+
27+
pub fn local_addr(&self) -> io::Result<SocketAddr> {
28+
SocketAddr::new(|addr, len| unsafe { getsockname(self.0.as_raw() as _, addr, len) })
29+
}
30+
#[stable(feature = "rust1", since = "1.0.0")]
31+
pub fn pair() -> io::Result<(Self, Self)> {
32+
unimplemented!()
33+
}
34+
#[stable(feature = "rust1", since = "1.0.0")]
35+
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
36+
SocketAddr::new(|addr, len| unsafe { getpeername(self.0.as_raw() as _, addr, len) })
37+
}
38+
#[stable(feature = "rust1", since = "1.0.0")]
39+
pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
40+
self.0.timeout(SO_RCVTIMEO)
41+
}
42+
#[stable(feature = "rust1", since = "1.0.0")]
43+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
44+
self.0.set_nonblocking(nonblocking)
45+
}
46+
#[stable(feature = "rust1", since = "1.0.0")]
47+
pub fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
48+
self.0.set_timeout(dur, SO_RCVTIMEO)
49+
}
50+
#[stable(feature = "rust1", since = "1.0.0")]
51+
pub fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
52+
self.0.set_timeout(dur, SO_SNDTIMEO)
53+
}
54+
#[stable(feature = "rust1", since = "1.0.0")]
55+
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
56+
self.0.shutdown(how)
57+
}
58+
#[stable(feature = "rust1", since = "1.0.0")]
59+
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
60+
self.0.take_error()
61+
}
62+
#[stable(feature = "rust1", since = "1.0.0")]
63+
pub fn try_clone(&self) -> io::Result<UnixStream> {
64+
self.0.duplicate().map(UnixStream)
65+
}
66+
#[stable(feature = "rust1", since = "1.0.0")]
67+
pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
68+
self.0.timeout(SO_SNDTIMEO)
69+
}
70+
}

0 commit comments

Comments
 (0)