public void WriteStringTest() { var f = Writer.Write("test"); f.GetCompletionEvent().Wait(); f = Writer.Write("foo"); f.GetCompletionEvent().Wait(); Assert.AreEqual(String.Empty, GetTestDataString()); f = Writer.Flush(); f.GetCompletionEvent().Wait(); Assert.AreEqual("testfoo", GetTestDataString()); }
static IEnumerator<object> PeerTask (TcpClient client, Peer peer) { var adapter = new SocketDataAdapter(client.Client, true); var input = new AsyncTextReader(adapter, Encoding.ASCII); var output = new AsyncTextWriter(adapter, Encoding.ASCII); adapter.ThrowOnDisconnect = false; adapter.ThrowOnFullSendBuffer = false; output.AutoFlush = true; peer.Input = input; peer.Output = output; yield return output.WriteLine("Welcome! Please enter your name."); string name = null; yield return input.ReadLine().Bind(() => name); if (name == null) { PeerDisconnected(peer); yield break; } peer.Name = name; PeerConnected(peer); yield return output.Write(VT100.EraseScreen); string nextLine = null; while (peer.Connected) { var f = input.ReadLine(); yield return f; if (!f.GetResult(out nextLine) || nextLine == null) { PeerDisconnected(peer); yield break; } if (nextLine.Length > 0) DispatchNewMessage(peer, nextLine); } }