@@ -723,6 +723,27 @@ impl IoContext {
723
723
724
724
/// Get read buffer
725
725
pub fn with_read_buf < F > ( & self , f : F ) -> Poll < ( ) >
726
+ where
727
+ F : FnOnce ( & mut BytesVec ) -> Poll < io:: Result < usize > > ,
728
+ {
729
+ let result = self . with_read_buf_inner ( f) ;
730
+
731
+ // check read readiness
732
+ if result. is_pending ( ) {
733
+ if let Some ( waker) = self . 0 . 0 . read_task . take ( ) {
734
+ let mut cx = Context :: from_waker ( & waker) ;
735
+
736
+ if let Poll :: Ready ( ReadStatus :: Ready ) =
737
+ self . 0 . filter ( ) . poll_read_ready ( & mut cx)
738
+ {
739
+ return Poll :: Pending ;
740
+ }
741
+ }
742
+ }
743
+ result
744
+ }
745
+
746
+ fn with_read_buf_inner < F > ( & self , f : F ) -> Poll < ( ) >
726
747
where
727
748
F : FnOnce ( & mut BytesVec ) -> Poll < io:: Result < usize > > ,
728
749
{
@@ -817,8 +838,33 @@ impl IoContext {
817
838
}
818
839
}
819
840
820
- /// Get write buffer
821
841
pub fn with_write_buf < F > ( & self , f : F ) -> Poll < ( ) >
842
+ where
843
+ F : FnOnce ( & BytesVec ) -> Poll < io:: Result < usize > > ,
844
+ {
845
+ let result = self . with_write_buf_inner ( f) ;
846
+
847
+ // check write readiness
848
+ if result. is_pending ( ) {
849
+ let inner = & self . 0 . 0 ;
850
+ if let Some ( waker) = inner. write_task . take ( ) {
851
+ let ready = self
852
+ . 0
853
+ . filter ( )
854
+ . poll_write_ready ( & mut Context :: from_waker ( & waker) ) ;
855
+ if !matches ! (
856
+ ready,
857
+ Poll :: Ready ( WriteStatus :: Ready | WriteStatus :: Shutdown )
858
+ ) {
859
+ return Poll :: Ready ( ( ) ) ;
860
+ }
861
+ }
862
+ }
863
+ result
864
+ }
865
+
866
+ /// Get write buffer
867
+ fn with_write_buf_inner < F > ( & self , f : F ) -> Poll < ( ) >
822
868
where
823
869
F : FnOnce ( & BytesVec ) -> Poll < io:: Result < usize > > ,
824
870
{
0 commit comments