@@ -248,70 +248,80 @@ impl Connection {
248248 executor. clone ( ) ,
249249 options. recovery_config . clone ( ) . unwrap_or_default ( ) ,
250250 ) ;
251- let status = conn. status . clone ( ) ;
252- let configuration = conn. configuration . clone ( ) ;
253- status. set_vhost ( & uri. vhost ) ;
254- status. set_username ( & uri. authority . userinfo . username ) ;
251+ conn. configure ( & uri) ;
252+ let stream = connect_promise
253+ . await
254+ . and_then ( |stream| reactor. register ( IOHandle :: new ( stream) ) . map_err ( Into :: into) )
255+ . inspect_err ( |_| {
256+ // We don't actually need the resolver as we already pass it around to the failing
257+ // code which will propagate the error. We only want to flush the status internal
258+ // state.
259+ let _ = conn. status . connection_resolver ( ) ;
260+ } ) ?
261+ . into ( ) ;
262+ let heartbeat = Heartbeat :: new (
263+ conn. status . clone ( ) ,
264+ conn. channels . clone ( ) ,
265+ executor. clone ( ) ,
266+ reactor,
267+ ) ;
268+ let io_loop = IoLoop :: new (
269+ conn. status . clone ( ) ,
270+ conn. configuration . clone ( ) ,
271+ conn. channels . clone ( ) ,
272+ internal_rpc. handle ( ) ,
273+ frames,
274+ socket_state,
275+ stream,
276+ heartbeat,
277+ ) ;
278+ executor. spawn ( Box :: pin ( internal_rpc. run ( conn. channels . clone ( ) ) ) ) ;
279+ io_loop. start ( & conn. io_loop ) ?;
280+ conn. start ( uri, options) . await
281+ }
282+
283+ fn configure ( & self , uri : & AMQPUri ) {
284+ self . status . set_vhost ( & uri. vhost ) ;
285+ self . status . set_username ( & uri. authority . userinfo . username ) ;
286+
255287 if let Some ( frame_max) = uri. query . frame_max {
256- configuration. set_frame_max ( frame_max) ;
288+ self . configuration . set_frame_max ( frame_max) ;
257289 }
258290 if let Some ( channel_max) = uri. query . channel_max {
259- configuration. set_channel_max ( channel_max) ;
291+ self . configuration . set_channel_max ( channel_max) ;
260292 }
261293 if let Some ( heartbeat) = uri. query . heartbeat {
262- configuration. set_heartbeat ( heartbeat) ;
294+ self . configuration . set_heartbeat ( heartbeat) ;
263295 }
264- let ( promise_out, resolver) = Promise :: new ( ) ;
296+ }
297+
298+ async fn start ( self , uri : AMQPUri , options : ConnectionProperties ) -> Result < Connection > {
299+ let ( promise_out, resolver_out) = Promise :: new ( ) ;
300+ let ( promise_in, resolver_in) = Promise :: new ( ) ;
265301 if level_enabled ! ( Level :: TRACE ) {
266302 promise_out. set_marker ( "ProtocolHeader" . into ( ) ) ;
303+ promise_in. set_marker ( "ProtocolHeader.Ok" . into ( ) ) ;
267304 }
268- let channels = conn . channels . clone ( ) ;
269- if let Some ( channel0) = channels. get ( 0 ) {
305+
306+ if let Some ( channel0) = self . channels . get ( 0 ) {
270307 channel0. send_frame (
271308 AMQPFrame :: ProtocolHeader ( ProtocolVersion :: amqp_0_9_1 ( ) ) ,
272- resolver ,
309+ resolver_out ,
273310 None ,
274311 )
275- } ;
276- let ( promise_in, resolver) = Promise :: new ( ) ;
277- if level_enabled ! ( Level :: TRACE ) {
278- promise_in. set_marker ( "ProtocolHeader.Ok" . into ( ) ) ;
279312 }
280- let io_loop_handle = conn. io_loop . clone ( ) ;
281- status. set_state ( ConnectionState :: Connecting ) ;
282- status. set_connection_step ( ConnectionStep :: ProtocolHeader (
283- resolver,
284- conn,
285- uri. authority . userinfo . into ( ) ,
286- uri. query . auth_mechanism . unwrap_or_default ( ) ,
287- options,
288- ) ) ;
289- let stream = connect_promise
290- . await
291- . and_then ( |stream| reactor. register ( IOHandle :: new ( stream) ) . map_err ( Into :: into) )
292- . inspect_err ( |_| {
293- // We don't actually need the resolver as we already pass it around to the failing
294- // code which will propagate the error. We only want to flush the status internal
295- // state.
296- let _ = status. connection_resolver ( ) ;
297- } ) ?
298- . into ( ) ;
299- let heartbeat = Heartbeat :: new ( status. clone ( ) , channels. clone ( ) , executor. clone ( ) , reactor) ;
300- let internal_rpc_handle = internal_rpc. handle ( ) ;
301- executor. spawn ( Box :: pin ( internal_rpc. run ( channels. clone ( ) ) ) ) ;
302- IoLoop :: new (
303- status,
304- configuration,
305- channels,
306- internal_rpc_handle,
307- frames,
308- socket_state,
309- io_loop_handle,
310- stream,
311- heartbeat,
312- )
313- . await
314- . and_then ( IoLoop :: start) ?;
313+
314+ self . status . set_state ( ConnectionState :: Connecting ) ;
315+ self . status
316+ . clone ( )
317+ . set_connection_step ( ConnectionStep :: ProtocolHeader (
318+ resolver_in,
319+ self ,
320+ uri. authority . userinfo . into ( ) ,
321+ uri. query . auth_mechanism . unwrap_or_default ( ) ,
322+ options,
323+ ) ) ;
324+
315325 promise_out. await ?;
316326 promise_in. await
317327 }
0 commit comments