@@ -3,14 +3,12 @@ use std::io;
3
3
use std:: net:: { SocketAddr , TcpListener as StdTcpListener } ;
4
4
use std:: time:: Duration ;
5
5
6
- use tokio:: net:: TcpListener ;
6
+ use tokio:: net:: { TcpListener , TcpStream } ;
7
7
use tokio:: time:: Sleep ;
8
8
use tracing:: { debug, error, trace} ;
9
9
10
10
use crate :: common:: { task, Future , Pin , Poll } ;
11
11
12
- #[ allow( unreachable_pub) ] // https://github.com/rust-lang/rust/issues/57411
13
- pub use self :: addr_stream:: AddrStream ;
14
12
use super :: accept:: Accept ;
15
13
16
14
/// A stream of connections from binding to an address.
@@ -98,7 +96,7 @@ impl AddrIncoming {
98
96
self . sleep_on_errors = val;
99
97
}
100
98
101
- fn poll_next_ ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < io:: Result < AddrStream > > {
99
+ fn poll_next_ ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < io:: Result < TcpStream > > {
102
100
// Check if a previous timeout is active that was set by IO errors.
103
101
if let Some ( ref mut to) = self . timeout {
104
102
ready ! ( Pin :: new( to) . poll( cx) ) ;
@@ -107,7 +105,7 @@ impl AddrIncoming {
107
105
108
106
loop {
109
107
match ready ! ( self . listener. poll_accept( cx) ) {
110
- Ok ( ( socket, remote_addr ) ) => {
108
+ Ok ( ( socket, _ ) ) => {
111
109
if let Some ( dur) = self . tcp_keepalive_timeout {
112
110
let socket = socket2:: SockRef :: from ( & socket) ;
113
111
let conf = socket2:: TcpKeepalive :: new ( ) . with_time ( dur) ;
@@ -118,8 +116,7 @@ impl AddrIncoming {
118
116
if let Err ( e) = socket. set_nodelay ( self . tcp_nodelay ) {
119
117
trace ! ( "error trying to set TCP nodelay: {}" , e) ;
120
118
}
121
- let local_addr = socket. local_addr ( ) ?;
122
- return Poll :: Ready ( Ok ( AddrStream :: new ( socket, remote_addr, local_addr) ) ) ;
119
+ return Poll :: Ready ( Ok ( socket) ) ;
123
120
}
124
121
Err ( e) => {
125
122
// Connection errors can be ignored directly, continue by
@@ -155,7 +152,7 @@ impl AddrIncoming {
155
152
}
156
153
157
154
impl Accept for AddrIncoming {
158
- type Conn = AddrStream ;
155
+ type Conn = TcpStream ;
159
156
type Error = io:: Error ;
160
157
161
158
fn poll_accept (
@@ -193,126 +190,3 @@ impl fmt::Debug for AddrIncoming {
193
190
. finish ( )
194
191
}
195
192
}
196
-
197
- mod addr_stream {
198
- use std:: io;
199
- use std:: net:: SocketAddr ;
200
- #[ cfg( unix) ]
201
- use std:: os:: unix:: io:: { AsRawFd , RawFd } ;
202
- use tokio:: io:: { AsyncRead , AsyncWrite , ReadBuf } ;
203
- use tokio:: net:: TcpStream ;
204
-
205
- use crate :: common:: { task, Pin , Poll } ;
206
-
207
- pin_project_lite:: pin_project! {
208
- /// A transport returned yieled by `AddrIncoming`.
209
- #[ derive( Debug ) ]
210
- pub struct AddrStream {
211
- #[ pin]
212
- inner: TcpStream ,
213
- pub ( super ) remote_addr: SocketAddr ,
214
- pub ( super ) local_addr: SocketAddr
215
- }
216
- }
217
-
218
- impl AddrStream {
219
- pub ( super ) fn new (
220
- tcp : TcpStream ,
221
- remote_addr : SocketAddr ,
222
- local_addr : SocketAddr ,
223
- ) -> AddrStream {
224
- AddrStream {
225
- inner : tcp,
226
- remote_addr,
227
- local_addr,
228
- }
229
- }
230
-
231
- /// Returns the remote (peer) address of this connection.
232
- #[ inline]
233
- pub fn remote_addr ( & self ) -> SocketAddr {
234
- self . remote_addr
235
- }
236
-
237
- /// Returns the local address of this connection.
238
- #[ inline]
239
- pub fn local_addr ( & self ) -> SocketAddr {
240
- self . local_addr
241
- }
242
-
243
- /// Consumes the AddrStream and returns the underlying IO object
244
- #[ inline]
245
- pub fn into_inner ( self ) -> TcpStream {
246
- self . inner
247
- }
248
-
249
- /// Attempt to receive data on the socket, without removing that data
250
- /// from the queue, registering the current task for wakeup if data is
251
- /// not yet available.
252
- pub fn poll_peek (
253
- & mut self ,
254
- cx : & mut task:: Context < ' _ > ,
255
- buf : & mut tokio:: io:: ReadBuf < ' _ > ,
256
- ) -> Poll < io:: Result < usize > > {
257
- self . inner . poll_peek ( cx, buf)
258
- }
259
- }
260
-
261
- impl AsyncRead for AddrStream {
262
- #[ inline]
263
- fn poll_read (
264
- self : Pin < & mut Self > ,
265
- cx : & mut task:: Context < ' _ > ,
266
- buf : & mut ReadBuf < ' _ > ,
267
- ) -> Poll < io:: Result < ( ) > > {
268
- self . project ( ) . inner . poll_read ( cx, buf)
269
- }
270
- }
271
-
272
- impl AsyncWrite for AddrStream {
273
- #[ inline]
274
- fn poll_write (
275
- self : Pin < & mut Self > ,
276
- cx : & mut task:: Context < ' _ > ,
277
- buf : & [ u8 ] ,
278
- ) -> Poll < io:: Result < usize > > {
279
- self . project ( ) . inner . poll_write ( cx, buf)
280
- }
281
-
282
- #[ inline]
283
- fn poll_write_vectored (
284
- self : Pin < & mut Self > ,
285
- cx : & mut task:: Context < ' _ > ,
286
- bufs : & [ io:: IoSlice < ' _ > ] ,
287
- ) -> Poll < io:: Result < usize > > {
288
- self . project ( ) . inner . poll_write_vectored ( cx, bufs)
289
- }
290
-
291
- #[ inline]
292
- fn poll_flush ( self : Pin < & mut Self > , _cx : & mut task:: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
293
- // TCP flush is a noop
294
- Poll :: Ready ( Ok ( ( ) ) )
295
- }
296
-
297
- #[ inline]
298
- fn poll_shutdown ( self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
299
- self . project ( ) . inner . poll_shutdown ( cx)
300
- }
301
-
302
- #[ inline]
303
- fn is_write_vectored ( & self ) -> bool {
304
- // Note that since `self.inner` is a `TcpStream`, this could
305
- // *probably* be hard-coded to return `true`...but it seems more
306
- // correct to ask it anyway (maybe we're on some platform without
307
- // scatter-gather IO?)
308
- self . inner . is_write_vectored ( )
309
- }
310
- }
311
-
312
- #[ cfg( unix) ]
313
- impl AsRawFd for AddrStream {
314
- fn as_raw_fd ( & self ) -> RawFd {
315
- self . inner . as_raw_fd ( )
316
- }
317
- }
318
- }
0 commit comments