/// <summary> /// (internal for tests only) /// Initializes a new instance of the <see cref="ClientMessageConnection"/> class. /// </summary> /// <param name="connection">The underlying <see cref="SocketConnectionBase"/>.</param> /// <param name="writerSemaphore">A writer-controlling semaphore.</param> /// <param name="loggerFactory">A logger factory.</param> internal ClientMessageConnection(SocketConnectionBase connection, IHSemaphore writerSemaphore, ILoggerFactory loggerFactory) { _connection = connection ?? throw new ArgumentNullException(nameof(connection)); _connection.OnReceiveMessageBytes = ReceiveMessageBytesAsync; _logger = loggerFactory?.CreateLogger <ClientMessageConnection>() ?? throw new ArgumentNullException(nameof(loggerFactory)); // TODO: threading control here could be an option // (in case threading control is performed elsewhere) _writer = writerSemaphore; }
/// <summary> /// Initializes a new instance of the <see cref="ClientMessageConnection"/> class. /// </summary> /// <param name="connection">The underlying <see cref="SocketConnectionBase"/>.</param> /// <param name="loggerFactory">A logger factory.</param> public ClientMessageConnection(SocketConnectionBase connection, ILoggerFactory loggerFactory) : this(connection, new HSemaphore(1, 1), loggerFactory) { }
private static ValueTask ReceivePrefixBytes(SocketConnectionBase connection, ReadOnlySequence <byte> bytes) { // do nothing for now - just accept them return(new ValueTask()); }
/// <summary> /// Handles a connection shutdown. /// </summary> /// <param name="connection">The connection.</param> /// <returns>A task that will complete when the connection shutdown has been handled.</returns> private ValueTask SocketShutdown(SocketConnectionBase connection) { HConsole.WriteLine(this, "Removing connection " + connection.Id); _connections.TryRemove(connection.Id, out _); return(default);
/// <summary> /// Handles a connection shutdown. /// </summary> /// <param name="connection">The connection.</param> /// <returns>A task that will complete when the connection shutdown has been handled.</returns> private void SocketShutdown(SocketConnectionBase connection) { HConsole.WriteLine(this, "Removing connection " + connection.Id); _connections.TryRemove(connection.Id, out _); }