@@ -28,7 +28,7 @@ use crate::{
28
28
async_lock:: RwLock ,
29
29
names:: { InterfaceName , UniqueName , WellKnownName } ,
30
30
object_server:: Interface ,
31
- Connection , Error , Executor , Guid , Result ,
31
+ Connection , Error , Executor , Guid , OwnedGuid , Result ,
32
32
} ;
33
33
34
34
use super :: {
@@ -161,7 +161,7 @@ impl<'a> Builder<'a> {
161
161
162
162
/// Create a builder for connection that will use the given socket.
163
163
pub fn socket < S : Socket + ' static > ( socket : S ) -> Self {
164
- Self :: new ( Target :: Socket ( Split :: new_boxed ( socket) ) )
164
+ Self :: new ( Target :: Socket ( socket. into ( ) ) )
165
165
}
166
166
167
167
/// Specify the mechanisms to use during authentication.
@@ -343,17 +343,11 @@ impl<'a> Builder<'a> {
343
343
}
344
344
345
345
async fn build_ ( mut self , executor : Executor < ' static > ) -> Result < Connection > {
346
- let mut stream = self . stream_for_target ( ) . await ?;
346
+ let ( mut stream, server_guid ) = self . target_connect ( ) . await ?;
347
347
let mut auth = match self . guid {
348
348
None => {
349
- let guid = match self . target {
350
- Some ( Target :: Address ( ref addr) ) => {
351
- addr. guid ( ) . map ( |guid| guid. to_owned ( ) . into ( ) )
352
- }
353
- _ => None ,
354
- } ;
355
349
// SASL Handshake
356
- Authenticated :: client ( stream, guid , self . auth_mechanisms ) . await ?
350
+ Authenticated :: client ( stream, server_guid , self . auth_mechanisms ) . await ?
357
351
}
358
352
Some ( guid) => {
359
353
if !self . p2p {
@@ -456,36 +450,42 @@ impl<'a> Builder<'a> {
456
450
}
457
451
}
458
452
459
- async fn stream_for_target ( & mut self ) -> Result < BoxedSplit > {
460
- // SAFETY: `self.target` is always `Some` from the beginning and this methos is only called
453
+ async fn target_connect ( & mut self ) -> Result < ( BoxedSplit , Option < OwnedGuid > ) > {
454
+ // SAFETY: `self.target` is always `Some` from the beginning and this method is only called
461
455
// once.
462
- Ok ( match self . target . take ( ) . unwrap ( ) {
456
+ let split = match self . target . take ( ) . unwrap ( ) {
463
457
#[ cfg( not( feature = "tokio" ) ) ]
464
- Target :: UnixStream ( stream) => Split :: new_boxed ( Async :: new ( stream) ?) ,
458
+ Target :: UnixStream ( stream) => Async :: new ( stream) ?. into ( ) ,
465
459
#[ cfg( all( unix, feature = "tokio" ) ) ]
466
- Target :: UnixStream ( stream) => Split :: new_boxed ( stream) ,
460
+ Target :: UnixStream ( stream) => stream. into ( ) ,
467
461
#[ cfg( all( not( unix) , feature = "tokio" ) ) ]
468
462
Target :: UnixStream ( _) => return Err ( Error :: Unsupported ) ,
469
463
#[ cfg( not( feature = "tokio" ) ) ]
470
- Target :: TcpStream ( stream) => Split :: new_boxed ( Async :: new ( stream) ?) ,
464
+ Target :: TcpStream ( stream) => Async :: new ( stream) ?. into ( ) ,
471
465
#[ cfg( feature = "tokio" ) ]
472
- Target :: TcpStream ( stream) => Split :: new_boxed ( stream) ,
466
+ Target :: TcpStream ( stream) => stream. into ( ) ,
473
467
#[ cfg( all( feature = "vsock" , not( feature = "tokio" ) ) ) ]
474
- Target :: VsockStream ( stream) => Split :: new_boxed ( Async :: new ( stream) ?) ,
468
+ Target :: VsockStream ( stream) => Async :: new ( stream) ?. into ( ) ,
475
469
#[ cfg( feature = "tokio-vsock" ) ]
476
- Target :: VsockStream ( stream) => Split :: new_boxed ( stream) ,
477
- Target :: Address ( address) => match address. connect ( ) . await ? {
478
- #[ cfg( any( unix, not( feature = "tokio" ) ) ) ]
479
- address:: transport:: Stream :: Unix ( stream) => Split :: new_boxed ( stream) ,
480
- address:: transport:: Stream :: Tcp ( stream) => Split :: new_boxed ( stream) ,
481
- #[ cfg( any(
482
- all( feature = "vsock" , not( feature = "tokio" ) ) ,
483
- feature = "tokio-vsock"
484
- ) ) ]
485
- address:: transport:: Stream :: Vsock ( stream) => Split :: new_boxed ( stream) ,
486
- } ,
470
+ Target :: VsockStream ( stream) => stream. into ( ) ,
471
+ Target :: Address ( address) => {
472
+ let guid = address. guid ( ) . map ( |g| g. to_owned ( ) . into ( ) ) ;
473
+ let split = match address. connect ( ) . await ? {
474
+ #[ cfg( any( unix, not( feature = "tokio" ) ) ) ]
475
+ address:: transport:: Stream :: Unix ( stream) => stream. into ( ) ,
476
+ address:: transport:: Stream :: Tcp ( stream) => stream. into ( ) ,
477
+ #[ cfg( any(
478
+ all( feature = "vsock" , not( feature = "tokio" ) ) ,
479
+ feature = "tokio-vsock"
480
+ ) ) ]
481
+ address:: transport:: Stream :: Vsock ( stream) => stream. into ( ) ,
482
+ } ;
483
+ return Ok ( ( split, guid) ) ;
484
+ }
487
485
Target :: Socket ( stream) => stream,
488
- } )
486
+ } ;
487
+
488
+ Ok ( ( split, None ) )
489
489
}
490
490
}
491
491
0 commit comments