@@ -94,6 +94,12 @@ impl fmt::Debug for UnixStream {
9494 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
9595 let mut builder = fmt. debug_struct ( "UnixStream" ) ;
9696 builder. field ( "fd" , & self . 0 . raw ( ) ) ;
97+ if let Ok ( addr) = self . local_addr ( ) {
98+ builder. field ( "local" , & addr) ;
99+ }
100+ if let Ok ( addr) = self . peer_addr ( ) {
101+ builder. field ( "peer" , & addr) ;
102+ }
97103 builder. finish ( )
98104 }
99105}
@@ -171,6 +177,142 @@ impl UnixStream {
171177 self . 0 . duplicate ( ) . map ( UnixStream )
172178 }
173179
180+ /// Returns the socket address of the local half of this connection.
181+ ///
182+ /// # Examples
183+ ///
184+ /// ```no_run
185+ /// use std::os::unix::net::UnixStream;
186+ ///
187+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
188+ /// let addr = socket.local_addr().expect("Couldn't get local address");
189+ /// ```
190+ pub fn local_addr ( & self ) -> io:: Result < SocketAddr > {
191+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::local_addr unimplemented on redox" ) )
192+ }
193+
194+ /// Returns the socket address of the remote half of this connection.
195+ ///
196+ /// # Examples
197+ ///
198+ /// ```no_run
199+ /// use std::os::unix::net::UnixStream;
200+ ///
201+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
202+ /// let addr = socket.peer_addr().expect("Couldn't get peer address");
203+ /// ```
204+ pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
205+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::peer_addr unimplemented on redox" ) )
206+ }
207+
208+ /// Sets the read timeout for the socket.
209+ ///
210+ /// If the provided value is [`None`], then [`read`] calls will block
211+ /// indefinitely. An [`Err`] is returned if the zero [`Duration`] is passed to this
212+ /// method.
213+ ///
214+ /// [`None`]: ../../../../std/option/enum.Option.html#variant.None
215+ /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
216+ /// [`read`]: ../../../../std/io/trait.Read.html#tymethod.read
217+ /// [`Duration`]: ../../../../std/time/struct.Duration.html
218+ ///
219+ /// # Examples
220+ ///
221+ /// ```no_run
222+ /// use std::os::unix::net::UnixStream;
223+ /// use std::time::Duration;
224+ ///
225+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
226+ /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
227+ /// ```
228+ ///
229+ /// An [`Err`] is returned if the zero [`Duration`] is passed to this
230+ /// method:
231+ ///
232+ /// ```no_run
233+ /// use std::io;
234+ /// use std::os::unix::net::UnixStream;
235+ /// use std::time::Duration;
236+ ///
237+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
238+ /// let result = socket.set_read_timeout(Some(Duration::new(0, 0)));
239+ /// let err = result.unwrap_err();
240+ /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
241+ /// ```
242+ pub fn set_read_timeout ( & self , _timeout : Option < Duration > ) -> io:: Result < ( ) > {
243+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::set_read_timeout unimplemented on redox" ) )
244+ }
245+
246+ /// Sets the write timeout for the socket.
247+ ///
248+ /// If the provided value is [`None`], then [`write`] calls will block
249+ /// indefinitely. An [`Err`] is returned if the zero [`Duration`] is
250+ /// passed to this method.
251+ ///
252+ /// [`None`]: ../../../../std/option/enum.Option.html#variant.None
253+ /// [`Err`]: ../../../../std/result/enum.Result.html#variant.Err
254+ /// [`write`]: ../../../../std/io/trait.Write.html#tymethod.write
255+ /// [`Duration`]: ../../../../std/time/struct.Duration.html
256+ ///
257+ /// # Examples
258+ ///
259+ /// ```no_run
260+ /// use std::os::unix::net::UnixStream;
261+ /// use std::time::Duration;
262+ ///
263+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
264+ /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
265+ /// ```
266+ ///
267+ /// An [`Err`] is returned if the zero [`Duration`] is passed to this
268+ /// method:
269+ ///
270+ /// ```no_run
271+ /// use std::io;
272+ /// use std::net::UdpSocket;
273+ /// use std::time::Duration;
274+ ///
275+ /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap();
276+ /// let result = socket.set_write_timeout(Some(Duration::new(0, 0)));
277+ /// let err = result.unwrap_err();
278+ /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput)
279+ /// ```
280+ pub fn set_write_timeout ( & self , _timeout : Option < Duration > ) -> io:: Result < ( ) > {
281+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::set_write_timeout unimplemented on redox" ) )
282+ }
283+
284+ /// Returns the read timeout of this socket.
285+ ///
286+ /// # Examples
287+ ///
288+ /// ```no_run
289+ /// use std::os::unix::net::UnixStream;
290+ /// use std::time::Duration;
291+ ///
292+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
293+ /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout");
294+ /// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0)));
295+ /// ```
296+ pub fn read_timeout ( & self ) -> io:: Result < Option < Duration > > {
297+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::read_timeout unimplemented on redox" ) )
298+ }
299+
300+ /// Returns the write timeout of this socket.
301+ ///
302+ /// # Examples
303+ ///
304+ /// ```no_run
305+ /// use std::os::unix::net::UnixStream;
306+ /// use std::time::Duration;
307+ ///
308+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
309+ /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout");
310+ /// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0)));
311+ /// ```
312+ pub fn write_timeout ( & self ) -> io:: Result < Option < Duration > > {
313+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::write_timeout unimplemented on redox" ) )
314+ }
315+
174316 /// Moves the socket into or out of nonblocking mode.
175317 ///
176318 /// # Examples
@@ -203,6 +345,27 @@ impl UnixStream {
203345 pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
204346 Ok ( None )
205347 }
348+
349+ /// Shuts down the read, write, or both halves of this connection.
350+ ///
351+ /// This function will cause all pending and future I/O calls on the
352+ /// specified portions to immediately return with an appropriate value
353+ /// (see the documentation of [`Shutdown`]).
354+ ///
355+ /// [`Shutdown`]: ../../../../std/net/enum.Shutdown.html
356+ ///
357+ /// # Examples
358+ ///
359+ /// ```no_run
360+ /// use std::os::unix::net::UnixStream;
361+ /// use std::net::Shutdown;
362+ ///
363+ /// let socket = UnixStream::connect("/tmp/sock").unwrap();
364+ /// socket.shutdown(Shutdown::Both).expect("shutdown function failed");
365+ /// ```
366+ pub fn shutdown ( & self , _how : Shutdown ) -> io:: Result < ( ) > {
367+ Err ( Error :: new ( ErrorKind :: Other , "UnixStream::shutdown unimplemented on redox" ) )
368+ }
206369}
207370
208371impl io:: Read for UnixStream {
@@ -299,6 +462,9 @@ impl fmt::Debug for UnixListener {
299462 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
300463 let mut builder = fmt. debug_struct ( "UnixListener" ) ;
301464 builder. field ( "fd" , & self . 0 . raw ( ) ) ;
465+ if let Ok ( addr) = self . local_addr ( ) {
466+ builder. field ( "local" , & addr) ;
467+ }
302468 builder. finish ( )
303469 }
304470}
@@ -375,6 +541,21 @@ impl UnixListener {
375541 self . 0 . duplicate ( ) . map ( UnixListener )
376542 }
377543
544+ /// Returns the local socket address of this listener.
545+ ///
546+ /// # Examples
547+ ///
548+ /// ```no_run
549+ /// use std::os::unix::net::UnixListener;
550+ ///
551+ /// let listener = UnixListener::bind("/path/to/the/socket").unwrap();
552+ ///
553+ /// let addr = listener.local_addr().expect("Couldn't get local address");
554+ /// ```
555+ pub fn local_addr ( & self ) -> io:: Result < SocketAddr > {
556+ Err ( Error :: new ( ErrorKind :: Other , "UnixListener::local_addr unimplemented on redox" ) )
557+ }
558+
378559 /// Moves the socket into or out of nonblocking mode.
379560 ///
380561 /// # Examples
0 commit comments