Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously sends data to the Destination Server through an SSL connection given a write timeout.
        /// </summary>
        /// <param name="sslStream">Underlying SSL Stream.</param>
        /// <param name="buffer">Send request byte buffer.</param>
        /// <param name="writeTimeout">Socket Write Timeout.</param>
        /// <param name="cancellationTokenSourceManager">Cancellation Token Source manager.</param>
        public static async ValueTask WriteAsync(this SslStream sslStream, ReadOnlyMemory <byte> buffer, int writeTimeout, CancellationTokenSourceManager cancellationTokenSourceManager)
        {
            cancellationTokenSourceManager.Start(writeTimeout);

            await sslStream.WriteAsync(buffer, cancellationTokenSourceManager.Token);

            cancellationTokenSourceManager.Stop();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Asynchronously Connects to the Destination Server given a connect timeout.
        /// </summary>
        /// <param name="socket">Underlying socket.</param>
        /// <param name="host">Destination Host.</param>
        /// <param name="port">Destination Port.</param>
        /// <param name="connectTimeout">Socket Connect Timeout.</param>
        /// <param name="cancellationTokenSourceManager">Cancellation Token Source manager.</param>
        public static async ValueTask ConnectAsync(this Socket socket, string host, int port, int connectTimeout, CancellationTokenSourceManager cancellationTokenSourceManager)
        {
            cancellationTokenSourceManager.Start(connectTimeout);

            await socket.ConnectAsync(host, port, cancellationTokenSourceManager.Token);

            cancellationTokenSourceManager.Stop();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Asynchronously reads data from the Destination Server through an SSL connection given a read timeout.
        /// </summary>
        /// <param name="sslStream">Underlying SSL Stream.</param>
        /// <param name="buffer">Read byte buffer.</param>
        /// <param name="readTimeout">Socket Read Timeout.</param>
        /// <param name="cancellationTokenSourceManager">Cancellation Token Source manager.</param>
        /// <returns>Number of read bytes</returns>
        public static async ValueTask <int> ReadAsync(this SslStream sslStream, Memory <byte> buffer, int readTimeout, CancellationTokenSourceManager cancellationTokenSourceManager)
        {
            cancellationTokenSourceManager.Start(readTimeout);

            var readBytes = await sslStream.ReadAsync(buffer, cancellationTokenSourceManager.Token);

            cancellationTokenSourceManager.Stop();

            return(readBytes);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Asynchronously reads data from the Destination Server given a read timeout.
        /// </summary>
        /// <param name="socket">Underlying socket.</param>
        /// <param name="buffer">Read byte buffer.</param>
        /// <param name="readTimeout">Socket Read Timeout.</param>
        /// <param name="cancellationTokenSourceManager">Cancellation Token Source manager.</param>
        /// <returns>Number of read bytes</returns>
        public static async ValueTask <int> ReceiveAsync(this Socket socket, Memory <byte> buffer, int readTimeout, CancellationTokenSourceManager cancellationTokenSourceManager)
        {
            cancellationTokenSourceManager.Start(readTimeout);

            var readBytes = await socket.ReceiveAsync(buffer, SocketFlags.None, cancellationTokenSourceManager.Token);

            cancellationTokenSourceManager.Stop();

            return(readBytes);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Asynchronously sends data to the Destination Server given a write timeout.
        /// </summary>
        /// <param name="socket">Underlying socket.</param>
        /// <param name="buffer">Send request byte buffer.</param>
        /// <param name="writeTimeout">Socket Write Timeout.</param>
        /// <param name="cancellationTokenSourceManager">Cancellation Token Source manager.</param>
        /// <returns>Number of sent bytes</returns>
        public static async ValueTask <int> SendAsync(this Socket socket, ReadOnlyMemory <byte> buffer, int writeTimeout, CancellationTokenSourceManager cancellationTokenSourceManager)
        {
            cancellationTokenSourceManager.Start(writeTimeout);

            var sentBytes = await socket.SendAsync(buffer, SocketFlags.None, cancellationTokenSourceManager.Token);

            cancellationTokenSourceManager.Stop();

            return(sentBytes);
        }