@@ -421,12 +421,14 @@ public IConnection CreateConnection()
421421 /// returned by the EndpointResolverFactory. By default the configured
422422 /// hostname and port are used.
423423 /// </summary>
424+ /// <param name="cancellationToken">Cancellation token for this connection</param>
424425 /// <exception cref="BrokerUnreachableException">
425426 /// When the configured hostname was not reachable.
426427 /// </exception>
427- public ValueTask < IConnection > CreateConnectionAsync ( )
428+ public ValueTask < IConnection > CreateConnectionAsync (
429+ CancellationToken cancellationToken = default ( CancellationToken ) )
428430 {
429- return CreateConnectionAsync ( ClientProvidedName ) ;
431+ return CreateConnectionAsync ( ClientProvidedName , cancellationToken ) ;
430432 }
431433
432434 /// <summary>
@@ -459,12 +461,14 @@ public IConnection CreateConnection(string clientProvidedName)
459461 /// be used as a connection identifier, e.g. in HTTP API requests.
460462 /// This value is supposed to be human-readable.
461463 /// </param>
464+ /// <param name="cancellationToken">Cancellation token for this connection</param>
462465 /// <exception cref="BrokerUnreachableException">
463466 /// When the configured hostname was not reachable.
464467 /// </exception>
465- public ValueTask < IConnection > CreateConnectionAsync ( string clientProvidedName )
468+ public ValueTask < IConnection > CreateConnectionAsync ( string clientProvidedName ,
469+ CancellationToken cancellationToken = default ( CancellationToken ) )
466470 {
467- return CreateConnectionAsync ( EndpointResolverFactory ( LocalEndpoints ( ) ) , clientProvidedName ) ;
471+ return CreateConnectionAsync ( EndpointResolverFactory ( LocalEndpoints ( ) ) , clientProvidedName , cancellationToken ) ;
468472 }
469473
470474 /// <summary>
@@ -496,13 +500,15 @@ public IConnection CreateConnection(IEnumerable<string> hostnames)
496500 /// List of hostnames to use for the initial
497501 /// connection and recovery.
498502 /// </param>
503+ /// <param name="cancellationToken">Cancellation token for this connection</param>
499504 /// <returns>Open connection</returns>
500505 /// <exception cref="BrokerUnreachableException">
501506 /// When no hostname was reachable.
502507 /// </exception>
503- public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < string > hostnames )
508+ public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < string > hostnames ,
509+ CancellationToken cancellationToken = default ( CancellationToken ) )
504510 {
505- return CreateConnectionAsync ( hostnames , ClientProvidedName ) ;
511+ return CreateConnectionAsync ( hostnames , ClientProvidedName , cancellationToken ) ;
506512 }
507513
508514 /// <summary>
@@ -547,14 +553,16 @@ public IConnection CreateConnection(IEnumerable<string> hostnames, string client
547553 /// be used as a connection identifier, e.g. in HTTP API requests.
548554 /// This value is supposed to be human-readable.
549555 /// </param>
556+ /// <param name="cancellationToken">Cancellation token for this connection</param>
550557 /// <returns>Open connection</returns>
551558 /// <exception cref="BrokerUnreachableException">
552559 /// When no hostname was reachable.
553560 /// </exception>
554- public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < string > hostnames , string clientProvidedName )
561+ public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < string > hostnames , string clientProvidedName ,
562+ CancellationToken cancellationToken = default ( CancellationToken ) )
555563 {
556564 IEnumerable < AmqpTcpEndpoint > endpoints = hostnames . Select ( h => new AmqpTcpEndpoint ( h , Port , Ssl , MaxMessageSize ) ) ;
557- return CreateConnectionAsync ( EndpointResolverFactory ( endpoints ) , clientProvidedName ) ;
565+ return CreateConnectionAsync ( EndpointResolverFactory ( endpoints ) , clientProvidedName , cancellationToken ) ;
558566 }
559567
560568 /// <summary>
@@ -584,13 +592,15 @@ public IConnection CreateConnection(IEnumerable<AmqpTcpEndpoint> endpoints)
584592 /// List of endpoints to use for the initial
585593 /// connection and recovery.
586594 /// </param>
595+ /// <param name="cancellationToken">Cancellation token for this connection</param>
587596 /// <returns>Open connection</returns>
588597 /// <exception cref="BrokerUnreachableException">
589598 /// When no hostname was reachable.
590599 /// </exception>
591- public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < AmqpTcpEndpoint > endpoints )
600+ public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < AmqpTcpEndpoint > endpoints ,
601+ CancellationToken cancellationToken = default ( CancellationToken ) )
592602 {
593- return CreateConnectionAsync ( endpoints , ClientProvidedName ) ;
603+ return CreateConnectionAsync ( endpoints , ClientProvidedName , cancellationToken ) ;
594604 }
595605
596606 /// <summary>
@@ -632,13 +642,15 @@ public IConnection CreateConnection(IEnumerable<AmqpTcpEndpoint> endpoints, stri
632642 /// be used as a connection identifier, e.g. in HTTP API requests.
633643 /// This value is supposed to be human-readable.
634644 /// </param>
645+ /// <param name="cancellationToken">Cancellation token for this connection</param>
635646 /// <returns>Open connection</returns>
636647 /// <exception cref="BrokerUnreachableException">
637648 /// When no hostname was reachable.
638649 /// </exception>
639- public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < AmqpTcpEndpoint > endpoints , string clientProvidedName )
650+ public ValueTask < IConnection > CreateConnectionAsync ( IEnumerable < AmqpTcpEndpoint > endpoints , string clientProvidedName ,
651+ CancellationToken cancellationToken = default ( CancellationToken ) )
640652 {
641- return CreateConnectionAsync ( EndpointResolverFactory ( endpoints ) , clientProvidedName ) ;
653+ return CreateConnectionAsync ( EndpointResolverFactory ( endpoints ) , clientProvidedName , cancellationToken ) ;
642654 }
643655
644656 /// <summary>
@@ -669,7 +681,8 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
669681 }
670682 else
671683 {
672- IFrameHandler frameHandler = endpointResolver . SelectOne ( CreateFrameHandlerAsync ) . EnsureCompleted ( ) ;
684+ IFrameHandler frameHandler = endpointResolver . SelectOneAsync (
685+ CreateFrameHandlerAsync , CancellationToken . None ) . EnsureCompleted ( ) ;
673686 var c = new Connection ( config , frameHandler ) ;
674687 return ( Connection ) c . Open ( ) ;
675688 }
@@ -692,27 +705,29 @@ public IConnection CreateConnection(IEndpointResolver endpointResolver, string c
692705 /// be used as a connection identifier, e.g. in HTTP API requests.
693706 /// This value is supposed to be human-readable.
694707 /// </param>
708+ /// <param name="cancellationToken">Cancellation token for this connection</param>
695709 /// <returns>Open connection</returns>
696710 /// <exception cref="BrokerUnreachableException">
697711 /// When no hostname was reachable.
698712 /// </exception>
699- public async ValueTask < IConnection > CreateConnectionAsync ( IEndpointResolver endpointResolver , string clientProvidedName )
713+ public async ValueTask < IConnection > CreateConnectionAsync ( IEndpointResolver endpointResolver , string clientProvidedName ,
714+ CancellationToken cancellationToken = default ( CancellationToken ) )
700715 {
701716 ConnectionConfig config = CreateConfig ( clientProvidedName ) ;
702717 try
703718 {
704719 if ( AutomaticRecoveryEnabled )
705720 {
706721 var c = new AutorecoveringConnection ( config , endpointResolver ) ;
707- return await c . OpenAsync ( )
722+ return await c . OpenAsync ( cancellationToken )
708723 . ConfigureAwait ( false ) ;
709724 }
710725 else
711726 {
712- IFrameHandler frameHandler = await endpointResolver . SelectOne ( CreateFrameHandlerAsync )
727+ IFrameHandler frameHandler = await endpointResolver . SelectOneAsync ( CreateFrameHandlerAsync , cancellationToken )
713728 . ConfigureAwait ( false ) ;
714729 var c = new Connection ( config , frameHandler ) ;
715- return await c . OpenAsync ( )
730+ return await c . OpenAsync ( cancellationToken )
716731 . ConfigureAwait ( false ) ;
717732 }
718733 }
@@ -748,11 +763,11 @@ private ConnectionConfig CreateConfig(string clientProvidedName)
748763 CreateFrameHandlerAsync ) ;
749764 }
750765
751- internal async Task < IFrameHandler > CreateFrameHandlerAsync ( AmqpTcpEndpoint endpoint )
766+ internal async Task < IFrameHandler > CreateFrameHandlerAsync (
767+ AmqpTcpEndpoint endpoint , CancellationToken cancellationToken )
752768 {
753769 IFrameHandler fh = new SocketFrameHandler ( endpoint , SocketFactory , RequestedConnectionTimeout , SocketReadTimeout , SocketWriteTimeout ) ;
754- // TODO cancellation token
755- await fh . ConnectAsync ( default ( CancellationToken ) )
770+ await fh . ConnectAsync ( cancellationToken )
756771 . ConfigureAwait ( false ) ;
757772 return ConfigureFrameHandler ( fh ) ;
758773 }
0 commit comments