WaitForRequestBytes() public method

public WaitForRequestBytes ( ) : int
return int
Beispiel #1
0
        public void Start()
        {
            _IsShutdownInProgress = false;

            try
            {
                _Socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback, Website.Port);
            }
            catch (Exception e)
            {
                _Socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback, Website.Port);
            }

            Task.Factory.StartNew(() =>
            {
                while (!_IsShutdownInProgress)
                {
                    try
                    {
                        var acceptedSocket = _Socket.Accept();

                        Task.Factory.StartNew(() =>
                        {
                            if (!_IsShutdownInProgress)
                            {
                                var conn = new Connection(this, acceptedSocket);

                                // wait for at least some input
                                if (conn.WaitForRequestBytes() == 0)
                                {
                                    conn.WriteErrorAndClose(400);
                                    return;
                                }

                                // find or create host
                                var host = GetHost();
                                if (host == null)
                                {
                                    conn.WriteErrorAndClose(500);
                                    return;
                                }

                                // process request in worker app domain
                                host.ProcessRequest(conn);
                            }
                        });
                    }
                    catch
                    {
                        Thread.Sleep(100);
                    }
                }
            });
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _ipAddress, _port);
            //start the timer
            StartTimer();


            ThreadPool.QueueUserWorkItem(delegate
            {
                while (!_shutdownInProgress)
                {
                    try
                    {
                        Socket acceptedSocket = _socket.Accept();

                        ThreadPool.QueueUserWorkItem(delegate
                        {
                            if (!_shutdownInProgress)
                            {
                                var conn = new Connection(this, acceptedSocket);

                                // wait for at least some input
                                if (conn.WaitForRequestBytes() == 0)
                                {
                                    conn.WriteErrorAndClose(400);
                                    return;
                                }

                                // find or create host
                                Host host = GetHost();
                                if (host == null)
                                {
                                    conn.WriteErrorAndClose(500);
                                    return;
                                }

                                IncrementRequestCount();

                                // process request in worker app domain
                                host.ProcessRequest(conn);

                                DecrementRequestCount();
                            }
                        });
                    }
                    catch
                    {
                        Thread.Sleep(100);
                    }
                }
            });

            OnServerStarted(new ServerEventArgs(RootUrl));
        }
Beispiel #3
0
        public void Start()
        {
            try {
                _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _addressType, _port);
            }
            catch {
                _addressType = (_addressType == IPAddress.Any) ?
                               IPAddress.IPv6Any : IPAddress.IPv6Loopback;
                _socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, _addressType, _port);
            }

            ThreadPool.QueueUserWorkItem(delegate {
                while (!_shutdownInProgress)
                {
                    try {
                        Socket acceptedSocket = _socket.Accept();

                        ThreadPool.QueueUserWorkItem(delegate {
                            if (!_shutdownInProgress)
                            {
                                var conn = new Connection(this, acceptedSocket);

                                // wait for at least some input
                                if (conn.WaitForRequestBytes() == 0)
                                {
                                    conn.WriteErrorAndClose(400);
                                    return;
                                }

                                // find or create host
                                Host host = GetHost();
                                if (host == null)
                                {
                                    conn.WriteErrorAndClose(500);
                                    return;
                                }

                                // process request in worker app domain
                                host.ProcessRequest(conn);
                            }
                        });
                    }
                    catch {
                        Thread.Sleep(100);
                    }
                }
            });
        }
Beispiel #4
0
        public void Start()
        {
            try {
                _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback, _port);
            }
            catch {
                _socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback, _port);
            }

            ThreadPool.QueueUserWorkItem(delegate {
                while (!_shutdownInProgress) {
                    try {
                        Socket acceptedSocket = _socket.Accept();

                        ThreadPool.QueueUserWorkItem(delegate {
                            if (!_shutdownInProgress) {
                                var conn = new Connection(this, acceptedSocket);

                                // wait for at least some input
                                if (conn.WaitForRequestBytes() == 0) {
                                    conn.WriteErrorAndClose(400);
                                    return;
                                }

                                // find or create host
                                Host host = GetHost();
                                if (host == null) {
                                    conn.WriteErrorAndClose(500);
                                    return;
                                }

                                // process request in worker app domain
                                host.ProcessRequest(conn);
                            }
                        });
                    }
                    catch {
                        Thread.Sleep(100);
                    }
                }
            });
        }
Beispiel #5
0
        private void OnSocketAccept(object acceptedSocket)
        {
            if (!_shutdownInProgress) {
                Connection conn =  new Connection(this, (Socket)acceptedSocket);

                // wait for at least some input
                if (conn.WaitForRequestBytes() == 0) {
                    conn.WriteErrorAndClose(400);
                    return;
                }

                // find or create host
                Host host = GetHost();
                if (host == null) {
                    conn.WriteErrorAndClose(500);
                    return;
                }

                // process request in worker app domain
                host.ProcessRequest(conn);
            }
        }
        public void Start()
        {
            _IsShutdownInProgress = false;

            try
            {
                _Socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback, Website.Port);
            }
            catch(Exception e)
            {
                _Socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback, Website.Port);
            }

            Task.Factory.StartNew(() =>
                                      {
                                          while (!_IsShutdownInProgress)
                                          {
                                              try
                                              {
                                                  var acceptedSocket = _Socket.Accept();

                                                  Task.Factory.StartNew(() =>
                                                                            {
                                                                                if (!_IsShutdownInProgress)
                                                                                {
                                                                                    var conn = new Connection(this, acceptedSocket);

                                                                                    // wait for at least some input
                                                                                    if (conn.WaitForRequestBytes() == 0)
                                                                                    {
                                                                                        conn.WriteErrorAndClose(400);
                                                                                        return;
                                                                                    }

                                                                                    // find or create host
                                                                                    var host = GetHost();
                                                                                    if (host == null)
                                                                                    {
                                                                                        conn.WriteErrorAndClose(500);
                                                                                        return;
                                                                                    }

                                                                                    // process request in worker app domain
                                                                                    host.ProcessRequest(conn);
                                                                                }
                                                                            });
                                              }
                                              catch
                                              {
                                                  Thread.Sleep(100);
                                              }
                                          }
                                      });
        }