@@ -59,8 +59,8 @@ pub trait NetConnection: NetStream + AsRawFd + Debug {
59
59
60
60
fn shutdown ( & mut self , how : Shutdown ) -> io:: Result < ( ) > ;
61
61
62
- fn remote_addr ( & self ) -> Self :: Addr ;
63
- fn local_addr ( & self ) -> Self :: Addr ;
62
+ fn remote_addr ( & self ) -> io :: Result < Self :: Addr > ;
63
+ fn local_addr ( & self ) -> io :: Result < Self :: Addr > ;
64
64
65
65
fn set_read_timeout ( & mut self , dur : Option < Duration > ) -> io:: Result < ( ) > ;
66
66
fn set_write_timeout ( & mut self , dur : Option < Duration > ) -> io:: Result < ( ) > ;
@@ -104,13 +104,9 @@ impl NetConnection for TcpStream {
104
104
105
105
fn shutdown ( & mut self , how : Shutdown ) -> io:: Result < ( ) > { TcpStream :: shutdown ( self , how) }
106
106
107
- fn remote_addr ( & self ) -> Self :: Addr {
108
- TcpStream :: peer_addr ( self ) . expect ( "TCP stream doesn't know remote peer address" ) . into ( )
109
- }
107
+ fn remote_addr ( & self ) -> io:: Result < Self :: Addr > { Ok ( TcpStream :: peer_addr ( self ) ?. into ( ) ) }
110
108
111
- fn local_addr ( & self ) -> Self :: Addr {
112
- TcpStream :: local_addr ( self ) . expect ( "TCP stream doesn't has local address" ) . into ( )
113
- }
109
+ fn local_addr ( & self ) -> io:: Result < Self :: Addr > { Ok ( TcpStream :: local_addr ( self ) ?. into ( ) ) }
114
110
115
111
fn set_read_timeout ( & mut self , dur : Option < Duration > ) -> io:: Result < ( ) > {
116
112
TcpStream :: set_read_timeout ( self , dur)
@@ -229,20 +225,18 @@ impl NetConnection for socket2::Socket {
229
225
230
226
fn shutdown ( & mut self , how : Shutdown ) -> io:: Result < ( ) > { socket2:: Socket :: shutdown ( self , how) }
231
227
232
- fn remote_addr ( & self ) -> Self :: Addr {
233
- socket2:: Socket :: peer_addr ( self )
234
- . expect ( "net stream must use only connections" )
228
+ fn remote_addr ( & self ) -> io:: Result < Self :: Addr > {
229
+ Ok ( socket2:: Socket :: peer_addr ( self ) ?
235
230
. as_socket ( )
236
- . expect ( "net stream must use only connections" )
237
- . into ( )
231
+ . ok_or :: < io :: Error > ( io :: ErrorKind :: NotFound . into ( ) ) ?
232
+ . into ( ) )
238
233
}
239
234
240
- fn local_addr ( & self ) -> Self :: Addr {
241
- socket2:: Socket :: local_addr ( self )
242
- . expect ( "net stream doesn't has local socket" )
235
+ fn local_addr ( & self ) -> io:: Result < Self :: Addr > {
236
+ Ok ( socket2:: Socket :: local_addr ( self ) ?
243
237
. as_socket ( )
244
- . expect ( "net stream doesn't has local socket" )
245
- . into ( )
238
+ . ok_or :: < io :: Error > ( io :: ErrorKind :: NotFound . into ( ) ) ?
239
+ . into ( ) )
246
240
}
247
241
248
242
fn set_read_timeout ( & mut self , dur : Option < Duration > ) -> io:: Result < ( ) > {
0 commit comments