예제 #1
0
        public void TestDefaultTimeout()
        {
            bool okclient  = false;
            bool okserver  = false;
            bool pipeready = false;
            var  pipename  = "test.pipe." + RndCrypto.NextBytes(10).ToHex();
            var  tc        = new Thread(() =>
            {
                while (!pipeready)
                {
                    Thread.Sleep(50);
                }
                Thread.Sleep(50);
                using (var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.InOut, PipeOptions.Asynchronous))
                    using (var binary = new BinaryStream(pipe))
                    {
                        pipe.Connect();
                        Thread.Sleep(100);
                        binary.WriteString("TEST");
                        Thread.Sleep(500);
                        binary.WriteString("TEST");
                        Thread.Sleep(100);
                        binary.ReadString();
                        Thread.Sleep(500);
                        binary.ReadString();

                        Thread.Sleep(100);
                        okclient = true;
                    }
            });

            tc.Start();

            var ts = new Thread(() =>
            {
                using (var pipe = new NamedPipeServerStream(pipename, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                    using (var timeout = new TimeoutableStream(pipe))
                        using (var binary = new BinaryStream(timeout))
                        {
                            pipeready = true;
                            pipe.WaitForConnection();
                            binary.ReadString();
                            binary.ReadString();
                            binary.WriteString("TEST");
                            binary.WriteString("TEST");
                            Thread.Sleep(100);
                            okserver = true;
                        }
            });

            ts.Start();

            tc.Join();
            ts.Join();

            Assert.IsTrue(okclient);
            Assert.IsTrue(okserver);
        }
예제 #2
0
        public void TestDefaultTimeout()
        {
            bool okclient = false;
            bool okserver = false;
            bool pipeready = false;
            var pipename = "test.pipe." + RndCrypto.NextBytes(10).ToHex();
            var tc = new Thread(() =>
            {
                while (!pipeready) Thread.Sleep(50);
                Thread.Sleep(50);
                using (var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.InOut, PipeOptions.Asynchronous))
                using (var binary = new BinaryStream(pipe))
                {
                    pipe.Connect();
                    Thread.Sleep(100);
                    binary.WriteString("TEST");
                    Thread.Sleep(500);
                    binary.WriteString("TEST");
                    Thread.Sleep(100);
                    binary.ReadString();
                    Thread.Sleep(500);
                    binary.ReadString();

                    Thread.Sleep(100);
                    okclient = true;
                }
            });
            tc.Start();

            var ts = new Thread(() =>
            {
                using (var pipe = new NamedPipeServerStream(pipename, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                using (var timeout = new TimeoutableStream(pipe))
                using (var binary = new BinaryStream(timeout))
                {
                    pipeready = true;
                    pipe.WaitForConnection();
                    binary.ReadString();
                    binary.ReadString();
                    binary.WriteString("TEST");
                    binary.WriteString("TEST");
                    Thread.Sleep(100);
                    okserver = true;
                }
            });
            ts.Start();

            tc.Join();
            ts.Join();

            Assert.IsTrue(okclient);
            Assert.IsTrue(okserver);
        }