예제 #1
0
        /// <summary>Test setting some server options.</summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestServerOptions()
        {
            string TestPath = new FilePath(sockDir.GetDir(), "test_sock_server_options").GetAbsolutePath
                                  ();
            DomainSocket serv = DomainSocket.BindAndListen(TestPath);

            try
            {
                // Let's set a new receive buffer size
                int bufSize    = serv.GetAttribute(DomainSocket.ReceiveBufferSize);
                int newBufSize = bufSize / 2;
                serv.SetAttribute(DomainSocket.ReceiveBufferSize, newBufSize);
                int nextBufSize = serv.GetAttribute(DomainSocket.ReceiveBufferSize);
                Assert.Equal(newBufSize, nextBufSize);
                // Let's set a server timeout
                int newTimeout = 1000;
                serv.SetAttribute(DomainSocket.ReceiveTimeout, newTimeout);
                int nextTimeout = serv.GetAttribute(DomainSocket.ReceiveTimeout);
                Assert.Equal(newTimeout, nextTimeout);
                try
                {
                    serv.Accept();
                    NUnit.Framework.Assert.Fail("expected the accept() to time out and fail");
                }
                catch (SocketTimeoutException e)
                {
                    GenericTestUtils.AssertExceptionContains("accept(2) error: ", e);
                }
            }
            finally
            {
                serv.Close();
                NUnit.Framework.Assert.IsFalse(serv.IsOpen());
            }
        }