@@ -107,7 +107,7 @@ impl AddrIncoming {
107
107
108
108
loop {
109
109
match ready ! ( self . listener. poll_accept( cx) ) {
110
- Ok ( ( socket, addr ) ) => {
110
+ Ok ( ( socket, remote_addr ) ) => {
111
111
if let Some ( dur) = self . tcp_keepalive_timeout {
112
112
let socket = socket2:: SockRef :: from ( & socket) ;
113
113
let conf = socket2:: TcpKeepalive :: new ( ) . with_time ( dur) ;
@@ -118,7 +118,11 @@ impl AddrIncoming {
118
118
if let Err ( e) = socket. set_nodelay ( self . tcp_nodelay ) {
119
119
trace ! ( "error trying to set TCP nodelay: {}" , e) ;
120
120
}
121
- return Poll :: Ready ( Ok ( AddrStream :: new ( socket, addr) ) ) ;
121
+ return Poll :: Ready ( Ok ( AddrStream :: new (
122
+ socket,
123
+ remote_addr,
124
+ socket. local_addr ( ) ?,
125
+ ) ) ) ;
122
126
}
123
127
Err ( e) => {
124
128
// Connection errors can be ignored directly, continue by
@@ -174,9 +178,12 @@ impl Accept for AddrIncoming {
174
178
/// The timeout is useful to handle resource exhaustion errors like ENFILE
175
179
/// and EMFILE. Otherwise, could enter into tight loop.
176
180
fn is_connection_error ( e : & io:: Error ) -> bool {
177
- matches ! ( e. kind( ) , io:: ErrorKind :: ConnectionRefused
178
- | io:: ErrorKind :: ConnectionAborted
179
- | io:: ErrorKind :: ConnectionReset )
181
+ matches ! (
182
+ e. kind( ) ,
183
+ io:: ErrorKind :: ConnectionRefused
184
+ | io:: ErrorKind :: ConnectionAborted
185
+ | io:: ErrorKind :: ConnectionReset
186
+ )
180
187
}
181
188
182
189
impl fmt:: Debug for AddrIncoming {
@@ -207,14 +214,20 @@ mod addr_stream {
207
214
#[ pin]
208
215
inner: TcpStream ,
209
216
pub ( super ) remote_addr: SocketAddr ,
217
+ pub ( super ) local_addr: SocketAddr
210
218
}
211
219
}
212
220
213
221
impl AddrStream {
214
- pub ( super ) fn new ( tcp : TcpStream , addr : SocketAddr ) -> AddrStream {
222
+ pub ( super ) fn new (
223
+ tcp : TcpStream ,
224
+ remote_addr : SocketAddr ,
225
+ local_addr : SocketAddr ,
226
+ ) -> AddrStream {
215
227
AddrStream {
216
228
inner : tcp,
217
- remote_addr : addr,
229
+ remote_addr,
230
+ local_addr,
218
231
}
219
232
}
220
233
@@ -224,6 +237,12 @@ mod addr_stream {
224
237
self . remote_addr
225
238
}
226
239
240
+ /// Returns the local address of this connection.
241
+ #[ inline]
242
+ pub fn local_addr ( & self ) -> SocketAddr {
243
+ self . local_addr
244
+ }
245
+
227
246
/// Consumes the AddrStream and returns the underlying IO object
228
247
#[ inline]
229
248
pub fn into_inner ( self ) -> TcpStream {
0 commit comments