@@ -59,10 +59,11 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
59
59
/// To wait infinitely for the close operations to complete use <see cref="System.Threading.Timeout.InfiniteTimeSpan"/>.
60
60
/// </para>
61
61
/// </remarks>
62
- public static Task CloseAsync ( this IConnection connection , TimeSpan timeout )
62
+ public static async Task CloseAsync ( this IConnection connection , TimeSpan timeout )
63
63
{
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 ) ;
66
67
}
67
68
68
69
/// <summary>
@@ -82,10 +83,11 @@ public static Task CloseAsync(this IConnection connection, TimeSpan timeout)
82
83
/// Operation timeout.
83
84
/// </para>
84
85
/// </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 )
86
87
{
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 ) ;
89
91
}
90
92
91
93
/// <summary>
@@ -97,10 +99,12 @@ public static Task CloseAsync(this IConnection connection, ushort reasonCode, st
97
99
/// <see cref="IOException"/> during closing connection.
98
100
///This method waits infinitely for the in-progress close operation to complete.
99
101
/// </remarks>
100
- public static Task AbortAsync ( this IConnection connection )
102
+ public static async Task AbortAsync ( this IConnection connection )
101
103
{
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 ) ;
104
108
}
105
109
106
110
/// <summary>
@@ -116,10 +120,12 @@ public static Task AbortAsync(this IConnection connection)
116
120
/// A message indicating the reason for closing the connection
117
121
/// </para>
118
122
/// </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 )
120
124
{
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 ) ;
123
129
}
124
130
125
131
/// <summary>
@@ -135,10 +141,12 @@ public static Task AbortAsync(this IConnection connection, ushort reasonCode, st
135
141
/// To wait infinitely for the close operations to complete use <see cref="Timeout.Infinite"/>.
136
142
/// </para>
137
143
/// </remarks>
138
- public static Task AbortAsync ( this IConnection connection , TimeSpan timeout )
144
+ public static async Task AbortAsync ( this IConnection connection , TimeSpan timeout )
139
145
{
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 ) ;
142
150
}
143
151
144
152
/// <summary>
@@ -155,10 +163,12 @@ public static Task AbortAsync(this IConnection connection, TimeSpan timeout)
155
163
/// A message indicating the reason for closing the connection.
156
164
/// </para>
157
165
/// </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 )
159
167
{
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 ) ;
162
172
}
163
173
}
164
174
}
0 commit comments