Skip to content

Commit 1dfd943

Browse files
Allow return null from ConnectionListener.AcceptAsync (#41453)
Co-authored-by: Natalia Kondratyeva <knatalia@microsoft.com> Backport of #41442 to release/5.0 As it was discussed in #41304, with current System.Net.Connections APIs, listeners need to throw from AcceptAsync when shutting down since AcceptAsync cannot return null. This PR allows AcceptAsync to return null, to avoid unnecessary first-chance exceptions when listeners are gracefully shutting down.
1 parent cb2023c commit 1dfd943

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/libraries/System.Net.Connections/ref/System.Net.Connections.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public abstract partial class ConnectionListener : System.IAsyncDisposable, Syst
5252
protected ConnectionListener() { }
5353
public abstract System.Net.Connections.IConnectionProperties ListenerProperties { get; }
5454
public abstract System.Net.EndPoint? LocalEndPoint { get; }
55-
public abstract System.Threading.Tasks.ValueTask<System.Net.Connections.Connection> AcceptAsync(System.Net.Connections.IConnectionProperties? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
55+
public abstract System.Threading.Tasks.ValueTask<System.Net.Connections.Connection?> AcceptAsync(System.Net.Connections.IConnectionProperties? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
5656
public void Dispose() { }
5757
protected virtual void Dispose(bool disposing) { }
5858
public System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }

src/libraries/System.Net.Connections/src/System/Net/Connections/ConnectionListener.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public abstract class ConnectionListener : IAsyncDisposable, IDisposable
2727
/// <param name="options">Options used to create the connection, if any.</param>
2828
/// <param name="cancellationToken">A token used to cancel the asynchronous operation.</param>
2929
/// <returns>A <see cref="ValueTask{TResult}"/> for the <see cref="Connection"/>.</returns>
30-
public abstract ValueTask<Connection> AcceptAsync(IConnectionProperties? options = null, CancellationToken cancellationToken = default);
30+
public abstract ValueTask<Connection?> AcceptAsync(IConnectionProperties? options = null, CancellationToken cancellationToken = default);
3131

3232
public void Dispose()
3333
{

0 commit comments

Comments
 (0)