Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Add new method for parameterless Listen() (#42262)
Browse files Browse the repository at this point in the history
* Add new method for parameterless Listen()

This adds a parameterless overload for Listen(int) which passes in int.MaxValue as the default value. I changed existing tests that were explicitly using int.MaxValue or a random value to use the new overload with no parameter.

* Update src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs

Co-Authored-By: Stephen Toub <stoub@microsoft.com>
  • Loading branch information
madenwala and stephentoub committed Nov 1, 2019
1 parent 5f45a8d commit 8bdfd53
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/System.Net.Sockets/ref/System.Net.Sockets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public void GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, Sy
public byte[] GetSocketOption(System.Net.Sockets.SocketOptionLevel optionLevel, System.Net.Sockets.SocketOptionName optionName, int optionLength) { throw null; }
public int IOControl(int ioControlCode, byte[] optionInValue, byte[] optionOutValue) { throw null; }
public int IOControl(System.Net.Sockets.IOControlCode ioControlCode, byte[] optionInValue, byte[] optionOutValue) { throw null; }
public void Listen() { }
public void Listen(int backlog) { }
public bool Poll(int microSeconds, System.Net.Sockets.SelectMode mode) { throw null; }
public int Receive(byte[] buffer) { throw null; }
Expand Down
13 changes: 12 additions & 1 deletion src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,18 @@ public void Close(int timeout)
if (NetEventSource.IsEnabled) NetEventSource.Exit(this, timeout);
}

// Places a socket in a listening state.
/// <summary>
/// Places a <see cref="Socket"/> in a listening state.
/// </summary>
/// <remarks>
/// The maximum length of the pending connections queue will be determined automatically.
/// </remarks>
public void Listen() => Listen(int.MaxValue);

/// <summary>
/// Places a <see cref="Socket"/> in a listening state.
/// </summary>
/// <param name="backlog">The maximum length of the pending connections queue.</param>
public void Listen(int backlog)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, backlog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void CtorAndAccept_SocketNotKeptAliveViaInheritance(bool validateClientOu
using (var listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
listener.Listen(int.MaxValue);
listener.Listen();
EndPoint ep = listener.LocalEndPoint;
// Create a client and connect to that listener.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public void Connect_IPAddresses_Port_Throws_ObjectDisposed()
[Fact]
public void Listen_Throws_ObjectDisposed()
{
Assert.Throws<ObjectDisposedException>(() => GetDisposedSocket().Listen());
Assert.Throws<ObjectDisposedException>(() => GetDisposedSocket().Listen(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static async Task<List<WeakReference>> CreateHandlesAsync(bool clientAsy
using (var listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
listener.Listen(int.MaxValue);
listener.Listen();

for (int i = 0; i < 100; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public void ExclusiveAddressUseTcp()
a.ExclusiveAddressUse = true;

a.Bind(new IPEndPoint(IPAddress.Loopback, 0));
a.Listen(10);
a.Listen();
int port = (a.LocalEndPoint as IPEndPoint).Port;

using (Socket b = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
Expand Down Expand Up @@ -531,7 +531,7 @@ public void BindDuringTcpWait_Succeeds()
{
a.Bind(new IPEndPoint(IPAddress.Loopback, 0));
port = (a.LocalEndPoint as IPEndPoint).Port;
a.Listen(10);
a.Listen();

// Connect a client
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
Expand Down

0 comments on commit 8bdfd53

Please sign in to comment.