@@ -59,10 +59,11 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
5959 /// To wait infinitely for the close operations to complete use <see cref="System.Threading.Timeout.InfiniteTimeSpan"/>.
6060 /// </para>
6161 /// </remarks>
62- public static Task CloseAsync ( this IConnection connection , TimeSpan timeout )
62+ public static async Task CloseAsync ( this IConnection connection , TimeSpan timeout )
6363 {
64- return connection . CloseAsync ( Constants . ReplySuccess , "Goodbye" , timeout , false ,
65- CancellationToken . None ) ;
64+ using var cts = new CancellationTokenSource ( timeout ) ;
65+ await connection . CloseAsync ( Constants . ReplySuccess , "Goodbye" , timeout , false , cts . Token )
66+ . ConfigureAwait ( false ) ;
6667 }
6768
6869 /// <summary>
@@ -82,10 +83,11 @@ public static Task CloseAsync(this IConnection connection, TimeSpan timeout)
8283 /// Operation timeout.
8384 /// </para>
8485 /// </remarks>
85- public static Task CloseAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
86+ public static async Task CloseAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
8687 {
87- return connection . CloseAsync ( reasonCode , reasonText , timeout , false ,
88- CancellationToken . None ) ;
88+ using var cts = new CancellationTokenSource ( timeout ) ;
89+ await connection . CloseAsync ( reasonCode , reasonText , timeout , false , cts . Token )
90+ . ConfigureAwait ( false ) ;
8991 }
9092
9193 /// <summary>
@@ -97,10 +99,12 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
9799 /// <see cref="IOException"/> during closing connection.
98100 ///This method waits infinitely for the in-progress close operation to complete.
99101 /// </remarks>
100- public static Task AbortAsync ( this IConnection connection )
102+ public static async Task AbortAsync ( this IConnection connection )
101103 {
102- return connection . CloseAsync ( Constants . ReplySuccess , "Connection close forced" , InternalConstants . DefaultConnectionAbortTimeout , true ,
103- CancellationToken . None ) ;
104+ using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
105+ await connection . CloseAsync ( Constants . ReplySuccess ,
106+ "Connection close forced" , InternalConstants . DefaultConnectionAbortTimeout , true , cts . Token )
107+ . ConfigureAwait ( false ) ;
104108 }
105109
106110 /// <summary>
@@ -116,10 +120,12 @@ public static Task AbortAsync(this IConnection connection)
116120 /// A message indicating the reason for closing the connection
117121 /// </para>
118122 /// </remarks>
119- public static Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText )
123+ public static async Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText )
120124 {
121- return connection . CloseAsync ( reasonCode , reasonText , InternalConstants . DefaultConnectionAbortTimeout , true ,
122- CancellationToken . None ) ;
125+ using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
126+ await connection . CloseAsync ( reasonCode ,
127+ reasonText , InternalConstants . DefaultConnectionAbortTimeout , true , cts . Token )
128+ . ConfigureAwait ( false ) ;
123129 }
124130
125131 /// <summary>
@@ -135,10 +141,12 @@ public static Task AbortAsync(this IConnection connection, ushort reasonCode, st
135141 /// To wait infinitely for the close operations to complete use <see cref="Timeout.Infinite"/>.
136142 /// </para>
137143 /// </remarks>
138- public static Task AbortAsync ( this IConnection connection , TimeSpan timeout )
144+ public static async Task AbortAsync ( this IConnection connection , TimeSpan timeout )
139145 {
140- return connection . CloseAsync ( Constants . ReplySuccess , "Connection close forced" , timeout , true ,
141- CancellationToken . None ) ;
146+ using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
147+ await connection . CloseAsync ( Constants . ReplySuccess ,
148+ "Connection close forced" , timeout , true , cts . Token )
149+ . ConfigureAwait ( false ) ;
142150 }
143151
144152 /// <summary>
@@ -155,10 +163,12 @@ public static Task AbortAsync(this IConnection connection, TimeSpan timeout)
155163 /// A message indicating the reason for closing the connection.
156164 /// </para>
157165 /// </remarks>
158- public static Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
166+ public static async Task AbortAsync ( this IConnection connection , ushort reasonCode , string reasonText , TimeSpan timeout )
159167 {
160- return connection . CloseAsync ( reasonCode , reasonText , timeout , true ,
161- CancellationToken . None ) ;
168+ using var cts = new CancellationTokenSource ( InternalConstants . DefaultConnectionAbortTimeout ) ;
169+ await connection . CloseAsync ( reasonCode ,
170+ reasonText , timeout , true , cts . Token )
171+ . ConfigureAwait ( false ) ;
162172 }
163173 }
164174}
0 commit comments