MailKit.Net.Imap.ImapStream.ReadLine C# (CSharp) Method

ReadLine() private method

Reads a single line of input from the stream.
This method should be called in a loop until it returns true.
/// The stream has been disposed. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. ///
private ReadLine ( byte &buffer, int &offset, int &count, CancellationToken cancellationToken ) : bool
buffer byte The buffer containing the line data.
offset int The offset into the buffer containing bytes read.
count int The number of bytes read.
cancellationToken System.Threading.CancellationToken The cancellation token.
return bool
		internal bool ReadLine (out byte[] buffer, out int offset, out int count, CancellationToken cancellationToken)
		{
			CheckDisposed ();

			unsafe {
				fixed (byte* inbuf = input) {
					byte* start, inptr, inend;

					// we need at least 1 byte: "\n"
					ReadAhead (1, cancellationToken);

					offset = inputIndex;
					buffer = input;

					start = inbuf + inputIndex;
					inend = inbuf + inputEnd;
					*inend = (byte) '\n';
					inptr = start;

					// FIXME: use SIMD to optimize this
					while (*inptr != (byte) '\n')
						inptr++;

					inputIndex = (int) (inptr - inbuf);
					count = (int) (inptr - start);

					if (inptr == inend)
						return false;

					// consume the '\n'
					inputIndex++;
					count++;

					return true;
				}
			}
		}