示例#1
0
        /// <summary>
        /// Read a line from the byte stream.
        /// </summary>
        /// <param name="client">The stream to read a line from.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The string that was read from the stream.</returns>
        public static async Task <IReadOnlyList <ArraySegment <byte> > > ReadLineAsync(this INetworkClient client, CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(Trim(await client.ReadUntilAsync(new byte[] { 13, 10 }, cancellationToken).ConfigureAwait(false), new byte[] { 13, 10 }));
        }
示例#2
0
        /// <summary>
        /// Read a dot terminated block.
        /// </summary>
        /// <param name="client">The stream to read a line from.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The buffers that were read until the block was terminated.</returns>
        public static async Task <IReadOnlyList <ArraySegment <byte> > > ReadDotBlockAsync(this INetworkClient client, CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var blocks = await client.ReadUntilAsync(new byte[] { 13, 10, 46, 13, 10 }, cancellationToken).ConfigureAwait(false);

            return(Unstuff(Trim(blocks, new byte[] { 13, 10, 46, 13, 10 })).ToList());
        }