@@ -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,8 @@ 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
+ let local_addr = socket. local_addr ( ) ?;
122
+ return Poll :: Ready ( Ok ( AddrStream :: new ( socket, remote_addr, local_addr) ) ) ;
122
123
}
123
124
Err ( e) => {
124
125
// Connection errors can be ignored directly, continue by
@@ -174,9 +175,12 @@ impl Accept for AddrIncoming {
174
175
/// The timeout is useful to handle resource exhaustion errors like ENFILE
175
176
/// and EMFILE. Otherwise, could enter into tight loop.
176
177
fn is_connection_error ( e : & io:: Error ) -> bool {
177
- matches ! ( e. kind( ) , io:: ErrorKind :: ConnectionRefused
178
- | io:: ErrorKind :: ConnectionAborted
179
- | io:: ErrorKind :: ConnectionReset )
178
+ matches ! (
179
+ e. kind( ) ,
180
+ io:: ErrorKind :: ConnectionRefused
181
+ | io:: ErrorKind :: ConnectionAborted
182
+ | io:: ErrorKind :: ConnectionReset
183
+ )
180
184
}
181
185
182
186
impl fmt:: Debug for AddrIncoming {
@@ -207,14 +211,20 @@ mod addr_stream {
207
211
#[ pin]
208
212
inner: TcpStream ,
209
213
pub ( super ) remote_addr: SocketAddr ,
214
+ pub ( super ) local_addr: SocketAddr
210
215
}
211
216
}
212
217
213
218
impl AddrStream {
214
- pub ( super ) fn new ( tcp : TcpStream , addr : SocketAddr ) -> AddrStream {
219
+ pub ( super ) fn new (
220
+ tcp : TcpStream ,
221
+ remote_addr : SocketAddr ,
222
+ local_addr : SocketAddr ,
223
+ ) -> AddrStream {
215
224
AddrStream {
216
225
inner : tcp,
217
- remote_addr : addr,
226
+ remote_addr,
227
+ local_addr,
218
228
}
219
229
}
220
230
@@ -224,6 +234,12 @@ mod addr_stream {
224
234
self . remote_addr
225
235
}
226
236
237
+ /// Returns the local address of this connection.
238
+ #[ inline]
239
+ pub fn local_addr ( & self ) -> SocketAddr {
240
+ self . local_addr
241
+ }
242
+
227
243
/// Consumes the AddrStream and returns the underlying IO object
228
244
#[ inline]
229
245
pub fn into_inner ( self ) -> TcpStream {
0 commit comments