~ruther/NosSmooth.Comms

ref: 2d0c91b61599398f037d97a8d6288736e01082d9 NosSmooth.Comms/src/Core/NosSmooth.Comms.Abstractions/IServer.cs -rw-r--r-- 1.3 KiB
2d0c91b6 — František Boháček chore: bump versions 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
//  IServer.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.ComponentModel;
using Remora.Results;

namespace NosSmooth.Comms.Data;

/// <summary>
/// An abstraction for a server.
/// </summary>
public interface IServer
{
    /// <summary>
    /// Gets the clients connected to the server.
    /// </summary>
    public IReadOnlyList<IConnection> Clients { get; }

    /// <summary>
    /// Listen for a new connection and wait for it.
    /// </summary>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A client connection, returned after the client has connected.</returns>
    public Task<Result<IConnection>> WaitForConnectionAsync(CancellationToken ct = default);

    /// <summary>
    /// Start the server.
    /// </summary>
    /// <param name="stopToken">The token used for stopping the server. <see cref="CloseAsync"/> may also be used.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> ListenAsync(CancellationToken stopToken = default);

    /// <summary>
    /// Close all connections, stop listening.
    /// </summary>
    public void Close();
}
Do not follow this link