@@ -119,7 +119,7 @@ struct ConnectionInner<S> {
119
119
raw_in_conn : Arc < Mutex < RawConnection < Async < S > > > > ,
120
120
// FIXME: We really should be using async_lock::Mutex here but `Sink::start_send is not very
121
121
// async friendly. :(
122
- sink : Arc < sync:: Mutex < MessageSink > > ,
122
+ raw_out_conn : Arc < sync:: Mutex < DynSocketConnection > > ,
123
123
// Serial number for next outgoing message
124
124
serial : AtomicU32 ,
125
125
@@ -751,10 +751,7 @@ impl Connection {
751
751
let out_socket = auth. conn . socket ( ) . get_ref ( ) . try_clone ( ) ?;
752
752
let out_conn = RawConnection :: wrap ( Async :: new ( out_socket) ?) ;
753
753
let cap_unix_fd = auth. cap_unix_fd ;
754
- let sink = Arc :: new ( sync:: Mutex :: new ( MessageSink {
755
- raw_conn : out_conn,
756
- cap_unix_fd,
757
- } ) ) ;
754
+ let raw_out_conn = Arc :: new ( sync:: Mutex :: new ( out_conn) ) ;
758
755
759
756
let ( mut msg_sender, msg_receiver) = broadcast ( DEFAULT_MAX_QUEUED ) ;
760
757
msg_sender. set_overflow ( true ) ;
@@ -772,7 +769,7 @@ impl Connection {
772
769
msg_receiver,
773
770
inner : Arc :: new ( ConnectionInner {
774
771
raw_in_conn,
775
- sink ,
772
+ raw_out_conn ,
776
773
server_guid : auth. server_guid ,
777
774
cap_unix_fd,
778
775
bus_conn : bus_connection,
@@ -828,39 +825,7 @@ impl Connection {
828
825
}
829
826
}
830
827
831
- #[ derive( Debug ) ]
832
- struct MessageSink {
833
- raw_conn : DynSocketConnection ,
834
- cap_unix_fd : bool ,
835
- }
836
-
837
- assert_impl_all ! ( MessageSink : Send , Sync , Unpin ) ;
838
-
839
- impl MessageSink {
840
- fn flush ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
841
- loop {
842
- match self . raw_conn . try_flush ( ) {
843
- Ok ( ( ) ) => return Poll :: Ready ( Ok ( ( ) ) ) ,
844
- Err ( e) => {
845
- if e. kind ( ) == ErrorKind :: WouldBlock {
846
- let poll = self . raw_conn . socket ( ) . poll_writable ( cx) ;
847
-
848
- match poll {
849
- Poll :: Pending => return Poll :: Pending ,
850
- // Guess socket became ready already so let's try it again.
851
- Poll :: Ready ( Ok ( _) ) => continue ,
852
- Poll :: Ready ( Err ( e) ) => return Poll :: Ready ( Err ( e. into ( ) ) ) ,
853
- }
854
- } else {
855
- return Poll :: Ready ( Err ( Error :: Io ( e) ) ) ;
856
- }
857
- }
858
- }
859
- }
860
- }
861
- }
862
-
863
- impl Sink < Message > for MessageSink {
828
+ impl Sink < Message > for Connection {
864
829
type Error = Error ;
865
830
866
831
fn poll_ready ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
@@ -869,48 +834,36 @@ impl Sink<Message> for MessageSink {
869
834
}
870
835
871
836
fn start_send ( self : Pin < & mut Self > , msg : Message ) -> Result < ( ) > {
872
- if !msg. fds ( ) . is_empty ( ) && !self . cap_unix_fd {
837
+ if !msg. fds ( ) . is_empty ( ) && !self . inner . cap_unix_fd {
873
838
return Err ( Error :: Unsupported ) ;
874
839
}
875
840
876
- self . get_mut ( ) . raw_conn . enqueue_message ( msg) ;
841
+ self . inner
842
+ . raw_out_conn
843
+ . lock ( )
844
+ . expect ( "poisened lock" )
845
+ . enqueue_message ( msg) ;
877
846
878
847
Ok ( ( ) )
879
848
}
880
849
881
850
fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
882
- self . get_mut ( ) . flush ( cx)
851
+ self . inner
852
+ . raw_out_conn
853
+ . lock ( )
854
+ . expect ( "poisened lock" )
855
+ . flush ( cx)
883
856
}
884
857
885
858
fn poll_close ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
886
- let sink = self . get_mut ( ) ;
887
- match sink . flush ( cx) {
859
+ let mut raw_out_conn = self . inner . raw_out_conn . lock ( ) . expect ( "poisened lock" ) ;
860
+ match raw_out_conn . flush ( cx) {
888
861
Poll :: Ready ( Ok ( _) ) => ( ) ,
889
862
Poll :: Ready ( Err ( e) ) => return Poll :: Ready ( Err ( e) ) ,
890
863
Poll :: Pending => return Poll :: Pending ,
891
864
}
892
865
893
- Poll :: Ready ( sink. raw_conn . close ( ) )
894
- }
895
- }
896
-
897
- impl Sink < Message > for Connection {
898
- type Error = Error ;
899
-
900
- fn poll_ready ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
901
- Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_ready ( cx)
902
- }
903
-
904
- fn start_send ( self : Pin < & mut Self > , msg : Message ) -> Result < ( ) > {
905
- Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . start_send ( msg)
906
- }
907
-
908
- fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
909
- Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_flush ( cx)
910
- }
911
-
912
- fn poll_close ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
913
- Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_close ( cx)
866
+ Poll :: Ready ( raw_out_conn. close ( ) )
914
867
}
915
868
}
916
869
0 commit comments