コード例 #1
0
        public override int WaitForRequestBytes()
        {
            if (bufferIndex == -1)
            {
                return(m_conn.WaitForRequestBytes());
            }

            return(initialBytes.Length - bufferIndex);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: maikebing/DotNetTestKit
        private void ServeConnection(Socket acceptedSocket)
        {
            if (!_shutdownInProgress)
            {
                //Connection conn = new Connection(this, acceptedSocket, (System.Security.Cryptography.X509Certificates.X509Certificate)certificate);
                Connection conn = new Connection(this, acceptedSocket);

                if (conn.WaitForRequestBytes() == 0)
                {
                    conn.WriteErrorAndClose(400);
                    return;
                }

                ProcessRequest(conn);
            }
        }
コード例 #3
0
        public void Start()
        {
            _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _ipAddress, _port);

            //start the timer
            DecrementRequestCount();

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

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

                                if (conn.WaitForRequestBytes() == 0)
                                {
                                    conn.WriteErrorAndClose(400);
                                    return;
                                }

                                Host host = GetHost();

                                if (host == null)
                                {
                                    conn.WriteErrorAndClose(500);
                                    return;
                                }

                                IncrementRequestCount();
                                host.ProcessRequest(conn);
                            }
                        });
                    }
                    catch
                    {
                        Thread.Sleep(100);
                    }
                }
            });
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: MagnusVortex/OCTGN
        public void StartWithoutAssemblies()
        {
            _socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, _ipAddress, _port);

            //start the timer
            DecrementRequestCount();

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

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

                                                                                                  if (
                                                                                                      conn.
                                                                                                          WaitForRequestBytes
                                                                                                          () == 0)
                                                                                                  {
                                                                                                      conn.
                                                                                                          WriteErrorAndClose
                                                                                                          (400);
                                                                                                      return;
                                                                                                  }

                                                                                                  Host host = GetHost();

                                                                                                  if (host == null)
                                                                                                  {
                                                                                                      conn.
                                                                                                          WriteErrorAndClose
                                                                                                          (500);
                                                                                                      return;
                                                                                                  }

                                                                                                  IncrementRequestCount();
                                                                                                  host.ProcessRequest(
                                                                                                      conn);
                                                                                              }
                                                                                          });
                                                     }
                                                     catch
                                                     {
                                                         Thread.Sleep(100);
                                                     }
                                                 }
                                             });
        }