@@ -305,7 +305,9 @@ impl MessageReceiverTask<Box<dyn Socket>> {
305
305
///
306
306
/// [Monitor]: https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-become-monitor
307
307
#[ derive( Clone , Debug ) ]
308
- pub struct Connection ( Arc < ConnectionInner < Box < dyn Socket > > > ) ;
308
+ pub struct Connection {
309
+ inner : Arc < ConnectionInner < Box < dyn Socket > > > ,
310
+ }
309
311
310
312
assert_impl_all ! ( Connection : Send , Sync , Unpin ) ;
311
313
@@ -367,14 +369,14 @@ impl Connection {
367
369
/// Get a stream to receive incoming messages.
368
370
pub async fn stream ( & self ) -> MessageStream {
369
371
let msg_receiver = self
370
- . 0
372
+ . inner
371
373
. msg_receiver
372
374
. read ( )
373
375
// SAFETY: Not much we can do about a poisoned mutex.
374
376
. expect ( "poisoned lock" )
375
377
. activate_cloned ( )
376
378
. map ( Ok ) ;
377
- let error_stream = self . 0 . error_receiver . clone ( ) . map ( Err ) ;
379
+ let error_stream = self . inner . error_receiver . clone ( ) . map ( Err ) ;
378
380
let stream = stream_select ( error_stream, msg_receiver) . boxed ( ) ;
379
381
380
382
MessageStream { stream }
@@ -519,7 +521,7 @@ impl Connection {
519
521
///
520
522
/// This will return `false` for p2p connections.
521
523
pub fn is_bus ( & self ) -> bool {
522
- self . 0 . bus_conn
524
+ self . inner . bus_conn
523
525
}
524
526
525
527
/// Assigns a serial number to `msg` that is unique to this connection.
@@ -537,12 +539,12 @@ impl Connection {
537
539
538
540
/// The unique name as assigned by the message bus or `None` if not a message bus connection.
539
541
pub fn unique_name ( & self ) -> Option < & str > {
540
- self . 0 . unique_name . get ( ) . map ( |s| s. as_str ( ) )
542
+ self . inner . unique_name . get ( ) . map ( |s| s. as_str ( ) )
541
543
}
542
544
543
545
/// Max number of messages to queue.
544
546
pub fn max_queued ( & self ) -> usize {
545
- self . 0
547
+ self . inner
546
548
. msg_receiver
547
549
. read ( )
548
550
. expect ( "poisoned lock" )
@@ -575,7 +577,7 @@ impl Connection {
575
577
///# Ok::<_, Box<dyn Error + Send + Sync>>(())
576
578
/// ```
577
579
pub fn set_max_queued ( self , max : usize ) -> Self {
578
- self . 0
580
+ self . inner
579
581
. msg_receiver
580
582
. write ( )
581
583
. expect ( "poisoned lock" )
@@ -586,7 +588,7 @@ impl Connection {
586
588
587
589
/// The server's GUID.
588
590
pub fn server_guid ( & self ) -> & str {
589
- self . 0 . server_guid . as_str ( )
591
+ self . inner . server_guid . as_str ( )
590
592
}
591
593
592
594
/// The underlying executor.
@@ -625,12 +627,12 @@ impl Connection {
625
627
///
626
628
/// [tte]: https://docs.rs/async-executor/1.4.1/async_executor/struct.Executor.html#method.tick
627
629
pub fn executor ( & self ) -> & Executor < ' static > {
628
- & self . 0 . executor
630
+ & self . inner . executor
629
631
}
630
632
631
633
/// Get the raw file descriptor of this connection.
632
634
pub async fn as_raw_fd ( & self ) -> RawFd {
633
- ( self . 0 . raw_in_conn . lock ( ) . await . socket ( ) ) . as_raw_fd ( )
635
+ ( self . inner . raw_in_conn . lock ( ) . await . socket ( ) ) . as_raw_fd ( )
634
636
}
635
637
636
638
pub ( crate ) async fn subscribe_signal < ' s , E > (
@@ -645,7 +647,7 @@ impl Connection {
645
647
{
646
648
let signal = SignalInfo :: new ( sender, path, interface, signal_name) ?;
647
649
let hash = signal. calc_hash ( ) ;
648
- let mut subscriptions = self . 0 . signal_subscriptions . lock ( ) . await ;
650
+ let mut subscriptions = self . inner . signal_subscriptions . lock ( ) . await ;
649
651
match subscriptions. get_mut ( & hash) {
650
652
Some ( subscription) => subscription. num_subscribers += 1 ,
651
653
None => {
@@ -689,7 +691,7 @@ impl Connection {
689
691
}
690
692
691
693
pub ( crate ) async fn unsubscribe_signal_by_id ( & self , subscription_id : u64 ) -> Result < bool > {
692
- let mut subscriptions = self . 0 . signal_subscriptions . lock ( ) . await ;
694
+ let mut subscriptions = self . inner . signal_subscriptions . lock ( ) . await ;
693
695
match subscriptions. get_mut ( & subscription_id) {
694
696
Some ( subscription) => {
695
697
subscription. num_subscribers -= 1 ;
@@ -715,7 +717,7 @@ impl Connection {
715
717
716
718
pub ( crate ) fn queue_unsubscribe_signal ( & self , subscription_id : u64 ) {
717
719
let conn = self . clone ( ) ;
718
- self . 0
720
+ self . inner
719
721
. executor
720
722
. spawn ( async move {
721
723
// FIXME: Ignoring the errors here. We should at least log a message when we've
@@ -742,7 +744,7 @@ impl Connection {
742
744
let name = {
743
745
use futures_util:: future:: { select, Either } ;
744
746
745
- let executor = self . 0 . executor . clone ( ) ;
747
+ let executor = self . inner . executor . clone ( ) ;
746
748
let ticking_future = async move {
747
749
// Keep running as long as this task/future is not cancelled.
748
750
loop {
@@ -759,7 +761,7 @@ impl Connection {
759
761
}
760
762
} ;
761
763
762
- self . 0
764
+ self . inner
763
765
. unique_name
764
766
. set ( name)
765
767
// programmer (probably our) error if this fails.
@@ -793,20 +795,22 @@ impl Connection {
793
795
MessageReceiverTask :: new ( raw_in_conn. clone ( ) , msg_sender, error_sender)
794
796
. spawn ( & executor) ;
795
797
796
- let connection = Self ( Arc :: new ( ConnectionInner {
797
- raw_in_conn,
798
- sink,
799
- error_receiver,
800
- server_guid : auth. server_guid ,
801
- cap_unix_fd,
802
- bus_conn : bus_connection,
803
- serial : AtomicU32 :: new ( 1 ) ,
804
- unique_name : OnceCell :: new ( ) ,
805
- signal_subscriptions : Mutex :: new ( HashMap :: new ( ) ) ,
806
- msg_receiver : sync:: RwLock :: new ( msg_receiver) ,
807
- executor : executor. clone ( ) ,
808
- msg_receiver_task : sync:: Mutex :: new ( Some ( msg_receiver_task) ) ,
809
- } ) ) ;
798
+ let connection = Self {
799
+ inner : Arc :: new ( ConnectionInner {
800
+ raw_in_conn,
801
+ sink,
802
+ error_receiver,
803
+ server_guid : auth. server_guid ,
804
+ cap_unix_fd,
805
+ bus_conn : bus_connection,
806
+ serial : AtomicU32 :: new ( 1 ) ,
807
+ unique_name : OnceCell :: new ( ) ,
808
+ signal_subscriptions : Mutex :: new ( HashMap :: new ( ) ) ,
809
+ msg_receiver : sync:: RwLock :: new ( msg_receiver) ,
810
+ executor : executor. clone ( ) ,
811
+ msg_receiver_task : sync:: Mutex :: new ( Some ( msg_receiver_task) ) ,
812
+ } ) ,
813
+ } ;
810
814
811
815
#[ cfg( feature = "internal-executor" ) ]
812
816
std:: thread:: Builder :: new ( )
@@ -831,7 +835,7 @@ impl Connection {
831
835
}
832
836
833
837
fn next_serial ( & self ) -> u32 {
834
- self . 0 . serial . fetch_add ( 1 , SeqCst )
838
+ self . inner . serial . fetch_add ( 1 , SeqCst )
835
839
}
836
840
837
841
/// Create a `Connection` to the session/user message bus.
@@ -922,19 +926,19 @@ impl Sink<Message> for Connection {
922
926
type Error = Error ;
923
927
924
928
fn poll_ready ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
925
- Pin :: new ( & mut * self . 0 . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_ready ( cx)
929
+ Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_ready ( cx)
926
930
}
927
931
928
932
fn start_send ( self : Pin < & mut Self > , msg : Message ) -> Result < ( ) > {
929
- Pin :: new ( & mut * self . 0 . sink . lock ( ) . expect ( "poisoned lock" ) ) . start_send ( msg)
933
+ Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . start_send ( msg)
930
934
}
931
935
932
936
fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
933
- Pin :: new ( & mut * self . 0 . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_flush ( cx)
937
+ Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_flush ( cx)
934
938
}
935
939
936
940
fn poll_close ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) > > {
937
- Pin :: new ( & mut * self . 0 . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_close ( cx)
941
+ Pin :: new ( & mut * self . inner . sink . lock ( ) . expect ( "poisoned lock" ) ) . poll_close ( cx)
938
942
}
939
943
}
940
944
0 commit comments