Write() public method

public Write ( ) : SignalFuture
return SignalFuture
示例#1
0
文件: IOTests.cs 项目: sq/Libraries
        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());
        }
示例#2
0
        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);
            }
        }