Exemple #1
0
        public void HttpConnection_Receive_Fail()
        {
            EnhancedSocket sockListen = null;
            EnhancedSocket sockAccept = null;
            HttpConnection con;
            HttpRequest    request;
            HttpResponse   response;
            TimeSpan       orgTimeout;
            IAsyncResult   ar;

            orgTimeout = HttpStack.TimeoutSweepInterval;
            HttpStack.TimeoutSweepInterval = TimeSpan.FromMilliseconds(250);

            sockListen = new EnhancedSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sockListen.Bind(new IPEndPoint(IPAddress.Any, ServerPort));
            sockListen.Listen(10);

            try
            {
                ar = sockListen.BeginAccept(null, null);

                con = new HttpConnection(HttpOption.None);
                con.Connect("http://localhost:" + ServerPort.ToString());

                sockAccept = sockListen.EndAccept(ar);

                request = new HttpRequest("GET", "/foo.htm", null);
                request["Content-Length"] = request.Content.Size.ToString();

                ar = con.BeginQuery(request, DateTime.MaxValue, null, null);
                Thread.Sleep(100);

                sockAccept.Close();
                sockAccept = null;

                try
                {
                    response = con.EndQuery(ar);
                    Assert.Fail();
                }
                catch
                {
                }

                Assert.IsTrue(con.IsClosed);
                con.Close();
            }
            finally
            {
                HttpStack.TimeoutSweepInterval = orgTimeout;

                if (sockListen != null)
                {
                    sockListen.Close();
                }

                if (sockAccept != null)
                {
                    sockAccept.Close();
                }
            }
        }