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); } }
/// <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)); }
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); } } }); }
public void Start() { ThreadPool.QueueUserWorkItem(delegate { while (!_shutdownInProgress) { try { m2net.Request acceptedSocket = _mongrel2Connection.Receive(); 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); } } }); }