Пример #1
0
        /// <summary>
        /// Test that we get an AsynchronousCloseException when the DomainSocket
        /// we're using is closed during a read or write operation.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        private void TestAsyncCloseDuringIO(bool closeDuringWrite)
        {
            string TestPath = new FilePath(sockDir.GetDir(), "testAsyncCloseDuringIO(" + closeDuringWrite
                                           + ")").GetAbsolutePath();
            DomainSocket    serv           = DomainSocket.BindAndListen(TestPath);
            ExecutorService exeServ        = Executors.NewFixedThreadPool(2);
            Callable <Void> serverCallable = new _Callable_180(serv, closeDuringWrite);
            // The server just continues either writing or reading until someone
            // asynchronously closes the client's socket.  At that point, all our
            // reads return EOF, and writes get a socket error.
            Future <Void>   serverFuture   = exeServ.Submit(serverCallable);
            DomainSocket    clientConn     = DomainSocket.Connect(serv.GetPath());
            Callable <Void> clientCallable = new _Callable_213(closeDuringWrite, clientConn);
            // The client writes or reads until another thread
            // asynchronously closes the socket.  At that point, we should
            // get ClosedChannelException, or possibly its subclass
            // AsynchronousCloseException.
            Future <Void> clientFuture = exeServ.Submit(clientCallable);

            Thread.Sleep(500);
            clientConn.Close();
            serv.Close();
            clientFuture.Get(2, TimeUnit.Minutes);
            serverFuture.Get(2, TimeUnit.Minutes);
        }
Пример #2
0
        /// <summary>Test that we get a read result of -1 on EOF.</summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestSocketReadEof()
        {
            string TestPath = new FilePath(sockDir.GetDir(), "testSocketReadEof").GetAbsolutePath
                                  ();
            DomainSocket    serv     = DomainSocket.BindAndListen(TestPath);
            ExecutorService exeServ  = Executors.NewSingleThreadExecutor();
            Callable <Void> callable = new _Callable_109(serv);
            Future <Void>   future   = exeServ.Submit(callable);
            DomainSocket    conn     = DomainSocket.Connect(serv.GetPath());

            Thread.Sleep(50);
            conn.Close();
            serv.Close();
            future.Get(2, TimeUnit.Minutes);
        }