private void StabilizeClientState(bool forWrite = false) { lock (this.client.SyncLock) { if (this.readBytesLeft > 0) { this.client.WriteStream.Flush(); if (this.tempBuffer == null) { this.tempBuffer = new byte[64 * 1024]; } while (this.readBytesLeft > 0) { this.readBytesLeft -= this.client.ReadStream.Read(this.tempBuffer, 0, Math.Min(this.readBytesLeft, this.tempBuffer.Length)); } this.client.ReadReady(); } } if (!forWrite) { bool wait = false; if (this.writeResponsesQueue.TaskState == TaskState.Running) { this.writeResponsesQueue.Enqueue(delegate { this.writeResponsesQueue.Stop(); }); this.client.WriteStream.Flush(); wait = true; } if (wait) { this.writeResponsesQueue.WaitForAnyTaskState(PredicateUtils.ObjectNotEquals(TaskState.Running)); this.writeResponsesQueue.Reset(); } } if (this.errorResponse != null) { var localErrorResponse = this.errorResponse; this.errorResponse = null; localErrorResponse.ProcessError(); } }
/// <summary> /// Reads a string form the <see cref="TextReader"/> until a space is encountered /// </summary> /// <param name="reader">The reader to read from</param> /// <param name="maximumLength">The maximum number of characters to read</param> /// <param name="overflow">A bool that will return True if the maximumLength was reached before a full word was read</param> /// <returns>The string that was read</returns> public static string ReadWord(this TextReader reader, int maximumLength, out bool overflow) { return(reader.ReadWhile(PredicateUtils.ObjectNotEquals(' '), maximumLength, out overflow)); }
/// <summary> /// Reads a string form the <see cref="TextReader"/> until a space is encountered /// </summary> /// <param name="reader">The reader to read from</param> /// <returns>The string that was read</returns> public static string ReadWord(this TextReader reader) { return(reader.ReadWhile(PredicateUtils.ObjectNotEquals(' '))); }
/// <summary> /// Reads a string form the <see cref="TextReader"/> until a space is encountered /// </summary> /// <param name="reader">The reader to read from</param> /// <param name="maximumLength">The maximum number of characters to read</param> /// <returns>The string that was read</returns> public static string ReadWord(TextReader reader, int maximumLength) { return(reader.ReadWhile(PredicateUtils.ObjectNotEquals(' '), maximumLength)); }