Skip to content

Commit 197af95

Browse files
committed
use the term 'listener' instead of 'server', for objects that wait for connections from clients
1 parent 2f06f25 commit 197af95

File tree

16 files changed

+172
-172
lines changed

16 files changed

+172
-172
lines changed

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/IMuninNodeClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Smdn.Net.MuninNode.Transport;
1313
/// Provides an interface that abstracts the client implementation of
1414
/// the transport layer that connects to the <c>Munin-Node</c>.
1515
/// </summary>
16-
/// <seealso cref="IMuninNodeServer"/>
16+
/// <seealso cref="IMuninNodeListener"/>
1717
public interface IMuninNodeClient : IDisposable, IAsyncDisposable {
1818
/// <summary>
1919
/// Gets the <see cref="EndPoint"/> that is bound with this instance.

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/IMuninNodeServer.cs renamed to src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/IMuninNodeListener.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99
namespace Smdn.Net.MuninNode.Transport;
1010

1111
/// <summary>
12-
/// Provides an interface that abstracts the server implementation of
12+
/// Provides an interface that abstracts the listener implementation of
1313
/// the transport layer that accepts the connections to the <c>Munin-Node</c>.
1414
/// </summary>
1515
/// <seealso cref="IMuninNodeClient"/>
16-
/// <seealso cref="IMuninNodeServerFactory"/>
17-
public interface IMuninNodeServer : IDisposable, IAsyncDisposable {
16+
/// <seealso cref="IMuninNodeListenerFactory"/>
17+
public interface IMuninNodeListener : IDisposable, IAsyncDisposable {
1818
/// <summary>
1919
/// Gets the <see cref="EndPoint"/> that is bound with this instance.
2020
/// </summary>
21-
/// <exception cref="ObjectDisposedException">The server has been disposed.</exception>
22-
/// <exception cref="InvalidOperationException">The server is not started yet.</exception>
21+
/// <exception cref="ObjectDisposedException">The instance has been disposed.</exception>
22+
/// <exception cref="InvalidOperationException">The instance is not started yet.</exception>
2323
/// <value>
24-
/// <see langword="null"/> if this server does not have <see cref="EndPoint"/>.
24+
/// <see langword="null"/> if this instance does not have <see cref="EndPoint"/>.
2525
/// </value>
2626
EndPoint? EndPoint { get; }
2727

2828
/// <summary>
29-
/// Start the server and enable to accept connections from clients.
29+
/// Start the listener and enable to accept connections from clients.
3030
/// </summary>
3131
/// <param name="cancellationToken">
3232
/// The <see cref="CancellationToken"/> to monitor for cancellation requests.
3333
/// </param>
3434
/// <returns>
3535
/// The <see cref="ValueTask"/> that represents the asynchronous operation,
36-
/// starting the server.
36+
/// starting the listener.
3737
/// </returns>
3838
ValueTask StartAsync(CancellationToken cancellationToken);
3939

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/IMuninNodeServerFactory.cs renamed to src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/IMuninNodeListenerFactory.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88
namespace Smdn.Net.MuninNode.Transport;
99

1010
/// <summary>
11-
/// Provides an interface that abstracts the factory for creating
12-
/// server implementation of the transport layer used by <c>Munin-Node</c>.
11+
/// Provides an interface that abstracts the factory for creating the client
12+
/// listener implementation of the transport layer used by <c>Munin-Node</c>.
1313
/// </summary>
14-
/// <seealso cref="IMuninNodeServer"/>
15-
public interface IMuninNodeServerFactory {
14+
/// <seealso cref="IMuninNodeListener"/>
15+
public interface IMuninNodeListenerFactory {
1616
/// <summary>
17-
/// Creates and returns a <see cref="IMuninNodeServer"/> for the specific <c>Munin-Node</c>.
17+
/// Creates and returns a <see cref="IMuninNodeListener"/> for the specific <c>Munin-Node</c>.
1818
/// </summary>
1919
/// <param name="endPoint">
20-
/// The <see cref="EndPoint"/> that will be bound with the <see cref="IMuninNodeServer"/> used by the <c>Munin-Node</c> to be created.
20+
/// The <see cref="EndPoint"/> that will be bound with the <see cref="IMuninNodeListener"/> used by the <c>Munin-Node</c> to be created.
2121
/// </param>
2222
/// <param name="node">
23-
/// The <see cref="IMuninNode"/> representing the <c>Munin-Node</c> where the <see cref="IMuninNodeServer"/> to be created will be used.
23+
/// The <see cref="IMuninNode"/> representing the <c>Munin-Node</c> where the <see cref="IMuninNodeListener"/> to be created will be used.
2424
/// </param>
2525
/// <param name="cancellationToken">
2626
/// The <see cref="CancellationToken"/> to monitor for cancellation requests.
2727
/// </param>
2828
/// <remarks>
2929
/// The <paramref name="node"/> parameter should not be used to determine an endpoint to bind to.
3030
/// It is intended to be used as a key for the management and identification of the
31-
/// <see cref="IMuninNodeServer"/> that has been created.
31+
/// <see cref="IMuninNodeListener"/> that has been created.
3232
/// </remarks>
3333
/// <returns>
34-
/// The <see cref="ValueTask{IMuninNodeServer}"/> that represents the asynchronous operation,
35-
/// creating the <see cref="IMuninNodeServer"/> bound to the <paramref name="endPoint"/>.
34+
/// The <see cref="ValueTask{IMuninNodeListener}"/> that represents the asynchronous operation,
35+
/// creating the <see cref="IMuninNodeListener"/> bound to the <paramref name="endPoint"/>.
3636
/// </returns>
37-
ValueTask<IMuninNodeServer> CreateAsync(
37+
ValueTask<IMuninNodeListener> CreateAsync(
3838
EndPoint endPoint,
3939
IMuninNode node,
4040
CancellationToken cancellationToken
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
4+
using System;
5+
using System.Net.Sockets;
6+
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace Smdn.Net.MuninNode.Transport;
10+
11+
#pragma warning disable IDE0040
12+
partial class MuninNodeListener {
13+
#pragma warning disable IDE0040
14+
/// <remarks>
15+
/// This constructor is used to maintain the functionality of the old API of
16+
/// creating server sockets with the <see cref="NodeBase.CreateServerSocket"/>.
17+
/// </remarks>
18+
[Obsolete]
19+
private MuninNodeListener(Socket listener, ILogger? logger)
20+
{
21+
if (listener is null)
22+
throw new ArgumentNullException(nameof(listener));
23+
if (listener.LocalEndPoint is null)
24+
throw new ArgumentException(message: "Must be a socket already bound to an endpoint.", paramName: nameof(listener));
25+
26+
endPoint = listener.LocalEndPoint; // although set, this value would never be used
27+
this.listener = listener;
28+
this.logger = logger;
29+
}
30+
31+
[Obsolete]
32+
internal static MuninNodeListener CreateFromStartedSocket(Socket listener, ILogger? logger)
33+
{
34+
if (listener is null)
35+
throw new ArgumentNullException(nameof(listener));
36+
37+
return new(listener, logger);
38+
}
39+
}

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/MuninNodeServer.cs renamed to src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/MuninNodeListener.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212

1313
namespace Smdn.Net.MuninNode.Transport;
1414

15-
internal sealed partial class MuninNodeServer : IMuninNodeServer {
15+
internal sealed partial class MuninNodeListener : IMuninNodeListener {
1616
private readonly EndPoint endPoint;
1717
private readonly ILogger? logger;
1818
private readonly IServiceProvider? serviceProvider;
19-
private Socket? server;
19+
private Socket? listener;
2020
private bool isRunning;
2121

22-
public EndPoint? EndPoint => server?.LocalEndPoint;
22+
public EndPoint? EndPoint => listener?.LocalEndPoint;
2323

2424
private const bool EnableDualMode = true; // XXX: this should be configurable(?)
2525

26-
internal MuninNodeServer(EndPoint endPoint, IServiceProvider? serviceProvider)
26+
internal MuninNodeListener(EndPoint endPoint, IServiceProvider? serviceProvider)
2727
: this(
2828
endPoint: endPoint,
29-
logger: serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<MuninNodeServer>(),
29+
logger: serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<MuninNodeListener>(),
3030
serviceProvider: serviceProvider
3131
)
3232
{
3333
}
3434

35-
internal MuninNodeServer(EndPoint endPoint, ILogger? logger, IServiceProvider? serviceProvider)
35+
internal MuninNodeListener(EndPoint endPoint, ILogger? logger, IServiceProvider? serviceProvider)
3636
{
3737
this.endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
3838
this.logger = logger;
@@ -61,21 +61,21 @@ public async ValueTask DisposeAsync()
6161
ValueTask DisposeAsyncCore()
6262
{
6363
try {
64-
if (server is not null && server.Connected) {
64+
if (listener is not null && listener.Connected) {
6565
#if SYSTEM_NET_SOCKETS_SOCKET_DISCONNECTASYNC_REUSESOCKET_CANCELLATIONTOKEN
66-
await server.DisconnectAsync(reuseSocket: false).ConfigureAwait(false);
66+
await listener.DisconnectAsync(reuseSocket: false).ConfigureAwait(false);
6767
#else
68-
server.Disconnect(reuseSocket: false);
68+
listener.Disconnect(reuseSocket: false);
6969
#endif
7070
}
7171
}
7272
catch (SocketException) {
7373
// swallow
7474
}
7575

76-
server?.Close();
77-
server?.Dispose();
78-
server = null;
76+
listener?.Close();
77+
listener?.Dispose();
78+
listener = null;
7979

8080
#if !SYSTEM_NET_SOCKETS_SOCKET_DISCONNECTASYNC_REUSESOCKET_CANCELLATIONTOKEN
8181
return default;
@@ -89,16 +89,16 @@ private void Dispose(bool disposing)
8989
return;
9090

9191
try {
92-
if (server is not null && server.Connected)
93-
server.Disconnect(reuseSocket: false);
92+
if (listener is not null && listener.Connected)
93+
listener.Disconnect(reuseSocket: false);
9494
}
9595
catch (SocketException) {
9696
// swallow
9797
}
9898

99-
server?.Close();
100-
server?.Dispose();
101-
server = null!;
99+
listener?.Close();
100+
listener?.Dispose();
101+
listener = null!;
102102
}
103103

104104
public ValueTask StartAsync(CancellationToken cancellationToken)
@@ -107,19 +107,19 @@ public ValueTask StartAsync(CancellationToken cancellationToken)
107107
throw new InvalidOperationException("already started");
108108

109109
try {
110-
if (server is null) {
111-
server = CreateServerSocket(endPoint);
110+
if (listener is null) {
111+
listener = CreateServerSocket(endPoint);
112112
}
113113
else {
114-
// since the `server` has already been assigned to a bound socket, treat as running state
114+
// since the `listener` has already been assigned to a bound socket, treat as running state
115115
}
116116

117117
isRunning = true;
118118

119119
return default;
120120
}
121121
catch {
122-
server = null;
122+
listener = null;
123123

124124
throw;
125125
}
@@ -165,10 +165,10 @@ public async ValueTask<IMuninNodeClient> AcceptAsync(CancellationToken cancellat
165165
{
166166
if (!isRunning)
167167
throw new InvalidOperationException("not started or already closed");
168-
if (server is null)
169-
throw new InvalidOperationException("invalid state: server is not initialized");
168+
if (listener is null)
169+
throw new InvalidOperationException("invalid state: listener is not initialized");
170170

171-
var client = await server
171+
var client = await listener
172172
#if SYSTEM_NET_SOCKETS_SOCKET_ACCEPTASYNC_CANCELLATIONTOKEN
173173
.AcceptAsync(cancellationToken: cancellationToken)
174174
#else

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.Transport/MuninNodeServer.Obsolete.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode/LocalNode.Create.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ConcreteLocalNode(
4242
IServiceProvider? serviceProvider = null
4343
)
4444
: base(
45-
serverFactory: new ServerFactory(serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<LocalNode>()),
45+
listenerFactory: new ListenerFactory(serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<LocalNode>()),
4646
accessRule: accessRule ?? serviceProvider?.GetService<IAccessRule>(),
4747
logger: serviceProvider?.GetService<ILoggerFactory>()?.CreateLogger<LocalNode>()
4848
)
@@ -58,15 +58,15 @@ protected override EndPoint GetLocalEndPointToBind()
5858
port: port
5959
);
6060

61-
private new sealed class ServerFactory(ILogger? logger) : IMuninNodeServerFactory {
62-
public ValueTask<IMuninNodeServer> CreateAsync(
61+
private new sealed class ListenerFactory(ILogger? logger) : IMuninNodeListenerFactory {
62+
public ValueTask<IMuninNodeListener> CreateAsync(
6363
EndPoint endPoint,
6464
IMuninNode node,
6565
CancellationToken cancellationToken
6666
)
6767
#pragma warning disable CA2000
6868
=> new(
69-
new MuninNodeServer(
69+
new MuninNodeListener(
7070
endPoint: endPoint,
7171
logger: logger,
7272
serviceProvider: null

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode/LocalNode.Obsolete.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ partial class LocalNode {
2121
/// <param name="logger">
2222
/// The <see cref="ILogger"/> to report the situation.
2323
/// </param>
24-
[Obsolete($"Use a constructor overload that takes {nameof(IMuninNodeServerFactory)} as an argument.")]
24+
[Obsolete($"Use a constructor overload that takes {nameof(IMuninNodeListenerFactory)} as an argument.")]
2525
protected LocalNode(
2626
IAccessRule? accessRule,
2727
ILogger? logger = null
@@ -33,7 +33,7 @@ protected LocalNode(
3333
{
3434
}
3535

36-
[Obsolete($"Use {nameof(IMuninNodeServerFactory)} and {nameof(StartAsync)} instead.")]
36+
[Obsolete($"Use {nameof(IMuninNodeListenerFactory)} and {nameof(StartAsync)} instead.")]
3737
protected override Socket CreateServerSocket()
38-
=> MuninNodeServer.CreateServerSocket(endPoint: GetLocalEndPointToBind());
38+
=> MuninNodeListener.CreateServerSocket(endPoint: GetLocalEndPointToBind());
3939
}

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode/LocalNode.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public abstract partial class LocalNode : NodeBase {
1919
/// <summary>
2020
/// Initializes a new instance of the <see cref="LocalNode"/> class.
2121
/// </summary>
22-
/// <param name="serverFactory">
23-
/// The <see cref="IMuninNodeServerFactory"/> factory to create an <see cref="IMuninNodeServer"/> to be used in this instance.
24-
/// If <see langword="null"/>, the default <see cref="IMuninNodeServerFactory"/> implementation is used.
22+
/// <param name="listenerFactory">
23+
/// The <see cref="IMuninNodeListenerFactory"/> factory to create an <see cref="IMuninNodeListener"/> to be used in this instance.
24+
/// If <see langword="null"/>, the default <see cref="IMuninNodeListenerFactory"/> implementation is used.
2525
/// </param>
2626
/// <param name="accessRule">
2727
/// The <see cref="IAccessRule"/> to determine whether to accept or reject a remote host that connects to <see cref="LocalNode"/>.
@@ -30,29 +30,29 @@ public abstract partial class LocalNode : NodeBase {
3030
/// The <see cref="ILogger"/> to report the situation.
3131
/// </param>
3232
protected LocalNode(
33-
IMuninNodeServerFactory? serverFactory,
33+
IMuninNodeListenerFactory? listenerFactory,
3434
IAccessRule? accessRule,
3535
ILogger? logger
3636
)
3737
: base(
38-
serverFactory: serverFactory ?? ServerFactory.Instance,
38+
listenerFactory: listenerFactory ?? ListenerFactory.Instance,
3939
accessRule: accessRule,
4040
logger: logger
4141
)
4242
{
4343
}
4444

45-
private sealed class ServerFactory : IMuninNodeServerFactory {
46-
public static readonly ServerFactory Instance = new();
45+
private sealed class ListenerFactory : IMuninNodeListenerFactory {
46+
public static readonly ListenerFactory Instance = new();
4747

48-
public ValueTask<IMuninNodeServer> CreateAsync(
48+
public ValueTask<IMuninNodeListener> CreateAsync(
4949
EndPoint endPoint,
5050
IMuninNode node,
5151
CancellationToken cancellationToken
5252
)
5353
#pragma warning disable CA2000
5454
=> new(
55-
new MuninNodeServer(
55+
new MuninNodeListener(
5656
endPoint: endPoint,
5757
logger: null,
5858
serviceProvider: null

0 commit comments

Comments
 (0)