コード例 #1
0
        /// <summary>Test file descriptor passing.</summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestFdPassing()
        {
            string TestPath = new FilePath(sockDir.GetDir(), "test_sock").GetAbsolutePath();

            byte[] clientMsg1 = new byte[] { unchecked ((int)(0x11)), unchecked ((int)(0x22)),
                                             unchecked ((int)(0x33)), unchecked ((int)(0x44)), unchecked ((int)(0x55)), unchecked (
                                                 (int)(0x66)) };
            byte[] serverMsg1 = new byte[] { unchecked ((int)(0x31)), unchecked ((int)(0x30)),
                                             unchecked ((int)(0x32)), unchecked ((int)(0x34)), unchecked ((int)(0x31)), unchecked (
                                                 (int)(0x33)), unchecked ((int)(0x44)), unchecked ((int)(0x1)), unchecked ((int)(0x1
                                                                                                                                 )), unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ((int)(0x1)) };
            ArrayBlockingQueue <System.Exception> threadResults = new ArrayBlockingQueue <System.Exception
                                                                                          >(2);
            DomainSocket serv = DomainSocket.BindAndListen(TestPath);

            TestDomainSocket.PassedFile[] passedFiles = new TestDomainSocket.PassedFile[] { new
                                                                                            TestDomainSocket.PassedFile(1), new TestDomainSocket.PassedFile(2) };
            FileDescriptor[] passedFds = new FileDescriptor[passedFiles.Length];
            for (int i = 0; i < passedFiles.Length; i++)
            {
                passedFds[i] = passedFiles[i].GetInputStream().GetFD();
            }
            Thread serverThread = new _Thread_597(serv, clientMsg1, passedFds, serverMsg1
                                                  , threadResults);

            // Run server
            serverThread.Start();
            Thread clientThread = new _Thread_620(TestPath, clientMsg1, serverMsg1, passedFds
                                                  , passedFiles, threadResults);

            clientThread.Start();
            for (int i_1 = 0; i_1 < 2; i_1++)
            {
                System.Exception t = threadResults.Take();
                if (!(t is TestDomainSocket.Success))
                {
                    NUnit.Framework.Assert.Fail(t.Message + ExceptionUtils.GetStackTrace(t));
                }
            }
            serverThread.Join(120000);
            clientThread.Join(120000);
            serv.Close();
            foreach (TestDomainSocket.PassedFile pf in passedFiles)
            {
                pf.Cleanup();
            }
        }
コード例 #2
0
        /// <summary>Test a simple client/server interaction.</summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        internal virtual void TestClientServer1(Type writeStrategyClass, Type readStrategyClass
                                                , DomainSocket[] preConnectedSockets)
        {
            string TestPath = new FilePath(sockDir.GetDir(), "test_sock_client_server1").GetAbsolutePath
                                  ();

            byte[] clientMsg1 = new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x2)), unchecked (
                                                 (int)(0x3)), unchecked ((int)(0x4)), unchecked ((int)(0x5)), unchecked ((int)(0x6)) };
            byte[] serverMsg1 = new byte[] { unchecked ((int)(0x9)), unchecked ((int)(0x8)), unchecked (
                                                 (int)(0x7)), unchecked ((int)(0x6)), unchecked ((int)(0x5)) };
            byte clientMsg2   = unchecked ((int)(0x45));
            ArrayBlockingQueue <Exception> threadResults = new ArrayBlockingQueue <Exception>(2
                                                                                              );
            DomainSocket serv = (preConnectedSockets != null) ? null : DomainSocket.BindAndListen
                                    (TestPath);
            Thread serverThread = new _Thread_435(preConnectedSockets, serv, clientMsg1
                                                  , readStrategyClass, writeStrategyClass, serverMsg1, clientMsg2, threadResults);

            // Run server
            serverThread.Start();
            Thread clientThread = new _Thread_463(preConnectedSockets, TestPath, writeStrategyClass
                                                  , clientMsg1, readStrategyClass, serverMsg1, clientMsg2, threadResults);

            clientThread.Start();
            for (int i = 0; i < 2; i++)
            {
                Exception t = threadResults.Take();
                if (!(t is TestDomainSocket.Success))
                {
                    NUnit.Framework.Assert.Fail(t.Message + ExceptionUtils.GetStackTrace(t));
                }
            }
            serverThread.Join(120000);
            clientThread.Join(120000);
            if (serv != null)
            {
                serv.Close();
            }
        }