@@ -303,8 +303,8 @@ impl fmt::Debug for Incoming<'_> {
303
303
/// ```
304
304
pub struct TcpStream {
305
305
inner : Arc < Async < std:: net:: TcpStream > > ,
306
- readable : Option < Pin < Box < dyn Future < Output = io :: Result < ( ) > > + Send + Sync > > > ,
307
- writable : Option < Pin < Box < dyn Future < Output = io :: Result < ( ) > > + Send + Sync > > > ,
306
+ readable : Option < async_io :: Readable > ,
307
+ writable : Option < async_io :: Writable > ,
308
308
}
309
309
310
310
impl UnwindSafe for TcpStream { }
@@ -599,13 +599,12 @@ impl AsyncRead for TcpStream {
599
599
600
600
// Initialize the future to wait for readiness.
601
601
if self . readable . is_none ( ) {
602
- let inner = self . inner . clone ( ) ;
603
- self . readable = Some ( Box :: pin ( async move { inner. readable ( ) . await } ) ) ;
602
+ self . readable = Some ( self . inner . readable ( ) ) ;
604
603
}
605
604
606
605
// Poll the future for readiness.
607
606
if let Some ( f) = & mut self . readable {
608
- let res = ready ! ( f . as_mut ( ) . poll( cx) ) ;
607
+ let res = ready ! ( Pin :: new ( f ) . poll( cx) ) ;
609
608
self . readable = None ;
610
609
res?;
611
610
}
@@ -631,13 +630,12 @@ impl AsyncWrite for TcpStream {
631
630
632
631
// Initialize the future to wait for readiness.
633
632
if self . writable . is_none ( ) {
634
- let inner = self . inner . clone ( ) ;
635
- self . writable = Some ( Box :: pin ( async move { inner. writable ( ) . await } ) ) ;
633
+ self . writable = Some ( self . inner . writable ( ) ) ;
636
634
}
637
635
638
636
// Poll the future for readiness.
639
637
if let Some ( f) = & mut self . writable {
640
- let res = ready ! ( f . as_mut ( ) . poll( cx) ) ;
638
+ let res = ready ! ( Pin :: new ( f ) . poll( cx) ) ;
641
639
self . writable = None ;
642
640
res?;
643
641
}
@@ -657,13 +655,12 @@ impl AsyncWrite for TcpStream {
657
655
658
656
// Initialize the future to wait for readiness.
659
657
if self . writable . is_none ( ) {
660
- let inner = self . inner . clone ( ) ;
661
- self . writable = Some ( Box :: pin ( async move { inner. writable ( ) . await } ) ) ;
658
+ self . writable = Some ( self . inner . writable ( ) ) ;
662
659
}
663
660
664
661
// Poll the future for readiness.
665
662
if let Some ( f) = & mut self . writable {
666
- let res = ready ! ( f . as_mut ( ) . poll( cx) ) ;
663
+ let res = ready ! ( Pin :: new ( f ) . poll( cx) ) ;
667
664
self . writable = None ;
668
665
res?;
669
666
}
@@ -691,13 +688,12 @@ impl AsyncWrite for TcpStream {
691
688
692
689
// Initialize the future to wait for readiness.
693
690
if self . writable . is_none ( ) {
694
- let inner = self . inner . clone ( ) ;
695
- self . writable = Some ( Box :: pin ( async move { inner. writable ( ) . await } ) ) ;
691
+ self . writable = Some ( self . inner . writable ( ) ) ;
696
692
}
697
693
698
694
// Poll the future for readiness.
699
695
if let Some ( f) = & mut self . writable {
700
- let res = ready ! ( f . as_mut ( ) . poll( cx) ) ;
696
+ let res = ready ! ( Pin :: new ( f ) . poll( cx) ) ;
701
697
self . writable = None ;
702
698
res?;
703
699
}
0 commit comments