Skip to content

Commit c986310

Browse files
committed
Add is_unnamed on redox
1 parent 79bf00f commit c986310

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

src/libstd/sys/redox/ext/unixsocket.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ use sys::{cvt, fd::FileDesc, syscall};
2020

2121
#[stable(feature = "unix_socket", since = "1.10.0")]
2222
#[derive(Clone)]
23-
pub(crate) struct SocketAddr(());
23+
pub struct SocketAddr(());
2424

2525
impl SocketAddr {
2626
#[stable(feature = "unix_socket", since = "1.10.0")]
27-
pub(crate) fn as_pathname(&self) -> Option<&Path> {
27+
pub fn is_unnamed(&self) -> bool {
28+
false
29+
}
30+
#[stable(feature = "unix_socket", since = "1.10.0")]
31+
pub fn as_pathname(&self) -> Option<&Path> {
2832
None
2933
}
3034
}
@@ -36,7 +40,7 @@ impl fmt::Debug for SocketAddr {
3640
}
3741

3842
#[stable(feature = "unix_socket", since = "1.10.0")]
39-
pub(crate) struct UnixStream(FileDesc);
43+
pub struct UnixStream(FileDesc);
4044

4145
#[stable(feature = "unix_socket", since = "1.10.0")]
4246
impl fmt::Debug for UnixStream {
@@ -55,7 +59,7 @@ impl fmt::Debug for UnixStream {
5559

5660
impl UnixStream {
5761
#[stable(feature = "unix_socket", since = "1.10.0")]
58-
pub(crate) fn connect(path: &Path) -> io::Result<UnixStream> {
62+
pub fn connect(path: &Path) -> io::Result<UnixStream> {
5963
if let Some(s) = path.to_str() {
6064
cvt(syscall::open(format!("chan:{}", s), syscall::O_CLOEXEC))
6165
.map(FileDesc::new)
@@ -69,7 +73,7 @@ impl UnixStream {
6973
}
7074

7175
#[stable(feature = "unix_socket", since = "1.10.0")]
72-
pub(crate) fn pair() -> io::Result<(UnixStream, UnixStream)> {
76+
pub fn pair() -> io::Result<(UnixStream, UnixStream)> {
7377
let server = cvt(syscall::open("chan:", syscall::O_CREAT | syscall::O_CLOEXEC))
7478
.map(FileDesc::new)?;
7579
let client = server.duplicate_path(b"connect")?;
@@ -78,52 +82,52 @@ impl UnixStream {
7882
}
7983

8084
#[stable(feature = "unix_socket", since = "1.10.0")]
81-
pub(crate) fn try_clone(&self) -> io::Result<UnixStream> {
85+
pub fn try_clone(&self) -> io::Result<UnixStream> {
8286
self.0.duplicate().map(UnixStream)
8387
}
8488

8589
#[stable(feature = "unix_socket", since = "1.10.0")]
86-
pub(crate) fn local_addr(&self) -> io::Result<SocketAddr> {
90+
pub fn local_addr(&self) -> io::Result<SocketAddr> {
8791
Err(Error::new(ErrorKind::Other, "UnixStream::local_addr unimplemented on redox"))
8892
}
8993

9094
#[stable(feature = "unix_socket", since = "1.10.0")]
91-
pub(crate) fn peer_addr(&self) -> io::Result<SocketAddr> {
95+
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
9296
Err(Error::new(ErrorKind::Other, "UnixStream::peer_addr unimplemented on redox"))
9397
}
9498

9599
#[stable(feature = "unix_socket", since = "1.10.0")]
96-
pub(crate) fn set_read_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
100+
pub fn set_read_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
97101
Err(Error::new(ErrorKind::Other, "UnixStream::set_read_timeout unimplemented on redox"))
98102
}
99103

100104
#[stable(feature = "unix_socket", since = "1.10.0")]
101-
pub(crate) fn set_write_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
105+
pub fn set_write_timeout(&self, _timeout: Option<Duration>) -> io::Result<()> {
102106
Err(Error::new(ErrorKind::Other, "UnixStream::set_write_timeout unimplemented on redox"))
103107
}
104108

105109
#[stable(feature = "unix_socket", since = "1.10.0")]
106-
pub(crate) fn read_timeout(&self) -> io::Result<Option<Duration>> {
110+
pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
107111
Err(Error::new(ErrorKind::Other, "UnixStream::read_timeout unimplemented on redox"))
108112
}
109113

110114
#[stable(feature = "unix_socket", since = "1.10.0")]
111-
pub(crate) fn write_timeout(&self) -> io::Result<Option<Duration>> {
115+
pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
112116
Err(Error::new(ErrorKind::Other, "UnixStream::write_timeout unimplemented on redox"))
113117
}
114118

115119
#[stable(feature = "unix_socket", since = "1.10.0")]
116-
pub(crate) fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
120+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
117121
self.0.set_nonblocking(nonblocking)
118122
}
119123

120124
#[stable(feature = "unix_socket", since = "1.10.0")]
121-
pub(crate) fn take_error(&self) -> io::Result<Option<io::Error>> {
125+
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
122126
Ok(None)
123127
}
124128

125129
#[stable(feature = "unix_socket", since = "1.10.0")]
126-
pub(crate) fn shutdown(&self, _how: Shutdown) -> io::Result<()> {
130+
pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> {
127131
Err(Error::new(ErrorKind::Other, "UnixStream::shutdown unimplemented on redox"))
128132
}
129133
}
@@ -173,7 +177,7 @@ impl IntoRawFd for UnixStream {
173177
}
174178

175179
#[stable(feature = "unix_socket", since = "1.10.0")]
176-
pub(crate) struct UnixListener(FileDesc);
180+
pub struct UnixListener(FileDesc);
177181

178182
#[stable(feature = "unix_socket", since = "1.10.0")]
179183
impl fmt::Debug for UnixListener {
@@ -189,7 +193,7 @@ impl fmt::Debug for UnixListener {
189193

190194
impl UnixListener {
191195
#[stable(feature = "unix_socket", since = "1.10.0")]
192-
pub(crate) fn bind(path: &Path) -> io::Result<UnixListener> {
196+
pub fn bind(path: &Path) -> io::Result<UnixListener> {
193197
if let Some(s) = path.to_str() {
194198
cvt(syscall::open(format!("chan:{}", s), syscall::O_CREAT | syscall::O_CLOEXEC))
195199
.map(FileDesc::new)
@@ -203,27 +207,27 @@ impl UnixListener {
203207
}
204208

205209
#[stable(feature = "unix_socket", since = "1.10.0")]
206-
pub(crate) fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
210+
pub fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
207211
self.0.duplicate_path(b"listen").map(|fd| (UnixStream(fd), SocketAddr(())))
208212
}
209213

210214
#[stable(feature = "unix_socket", since = "1.10.0")]
211-
pub(crate) fn try_clone(&self) -> io::Result<UnixListener> {
215+
pub fn try_clone(&self) -> io::Result<UnixListener> {
212216
self.0.duplicate().map(UnixListener)
213217
}
214218

215219
#[stable(feature = "unix_socket", since = "1.10.0")]
216-
pub(crate) fn local_addr(&self) -> io::Result<SocketAddr> {
220+
pub fn local_addr(&self) -> io::Result<SocketAddr> {
217221
Err(Error::new(ErrorKind::Other, "UnixListener::local_addr unimplemented on redox"))
218222
}
219223

220224
#[stable(feature = "unix_socket", since = "1.10.0")]
221-
pub(crate) fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
225+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
222226
self.0.set_nonblocking(nonblocking)
223227
}
224228

225229
#[stable(feature = "unix_socket", since = "1.10.0")]
226-
pub(crate) fn take_error(&self) -> io::Result<Option<io::Error>> {
230+
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
227231
Ok(None)
228232
}
229233
}

src/libstd/sys/unix/ext/unixsocket.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub struct SocketAddr {
5454
}
5555

5656
impl SocketAddr {
57-
pub(crate) fn new<F>(f: F) -> io::Result<SocketAddr>
57+
#[stable(feature = "unix_socket", since = "1.10.0")]
58+
pub fn new<F>(f: F) -> io::Result<SocketAddr>
5859
where F: FnOnce(*mut libc::sockaddr, *mut libc::socklen_t) -> libc::c_int
5960
{
6061
unsafe {
@@ -65,7 +66,8 @@ impl SocketAddr {
6566
}
6667
}
6768

68-
pub(crate) fn from_parts(addr: libc::sockaddr_un, mut len: libc::socklen_t)
69+
#[stable(feature = "unix_socket", since = "1.10.0")]
70+
pub fn from_parts(addr: libc::sockaddr_un, mut len: libc::socklen_t)
6971
-> io::Result<SocketAddr>
7072
{
7173
if len == 0 {

src/libstd/sys_common/unixsocket.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@ impl<'a> io::Write for &'a UnixStream {
113113
}
114114

115115
impl SocketAddr {
116+
/// Returns true if and only if the address is unnamed.
117+
///
118+
/// # Examples
119+
///
120+
/// A named address:
121+
///
122+
/// ```no_run
123+
/// use std::os::unix::net::UnixListener;
124+
///
125+
/// let socket = UnixListener::bind("/tmp/sock").unwrap();
126+
/// let addr = socket.local_addr().expect("Couldn't get local address");
127+
/// assert_eq!(addr.is_unnamed(), false);
128+
/// ```
129+
///
130+
/// An unnamed address:
131+
///
132+
/// ```
133+
/// use std::os::unix::net::UnixDatagram;
134+
///
135+
/// let socket = UnixDatagram::unbound().unwrap();
136+
/// let addr = socket.local_addr().expect("Couldn't get local address");
137+
/// assert_eq!(addr.is_unnamed(), true);
138+
/// ```
139+
#[stable(feature = "unix_socket", since = "1.10.0")]
140+
pub fn is_unnamed(&self) -> bool {
141+
self.0.is_unnamed()
142+
}
143+
116144
/// Returns the contents of this address if it is a `pathname` address.
117145
///
118146
/// # Examples

0 commit comments

Comments
 (0)