2004-07-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* server/ApplicationServer.cs: increased the backlog for listen, set
	accepted sockets read/write timeout to 15s and handle timeouts when
	reading request data before submitting the work item to the threadpool.
	* server/XSPApplicationHost.cs: don't write a 500 error response if
	we got an IOException when reading from the network stream.
	* server/XSPWorkerRequest.cs: if there's an IOException when reading
	the headers, just rethrow it.

svn path=/trunk/xsp/; revision=31587
This commit is contained in:
Gonzalo Paniagua Javier 2004-07-28 20:24:42 +00:00
Родитель 925c8085a7
Коммит 078fc6e3f7
4 изменённых файлов: 69 добавлений и 9 удалений

Просмотреть файл

@ -1,3 +1,13 @@
2004-07-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* server/ApplicationServer.cs: increased the backlog for listen, set
accepted sockets read/write timeout to 15s and handle timeouts when
reading request data before submitting the work item to the threadpool.
* server/XSPApplicationHost.cs: don't write a 500 error response if
we got an IOException when reading from the network stream.
* server/XSPWorkerRequest.cs: if there's an IOException when reading
the headers, just rethrow it.
2004-07-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* server/ModMonoApplicationHost.cs: don't write the 50x error response

Просмотреть файл

@ -231,7 +231,7 @@ namespace Mono.ASPNET
throw new InvalidOperationException ("No applications defined.");
listen_socket = webSource.CreateSocket ();
listen_socket.Listen (5);
listen_socket.Listen (500);
runner = new Thread (new ThreadStart (RunServer));
runner.IsBackground = bgThread;
runner.Start ();
@ -255,15 +255,60 @@ namespace Mono.ASPNET
WebTrace.WriteLine ("Server stopped.");
}
private void RunServer ()
void SetSocketOptions (Socket sock)
{
sock.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 15000); // 15s
sock.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 15000); // 15s
}
ArrayList allSockets = new ArrayList ();
ArrayList wSockets = new ArrayList ();
Hashtable timeouts = new Hashtable ();
void RunServer ()
{
allSockets.Add (listen_socket);
wSockets.Add (listen_socket);
started = true;
Socket client;
int w;
while (!stop){
client = listen_socket.Accept ();
WebTrace.WriteLine ("Accepted connection.");
IWorker worker = webSource.CreateWorker (client, this);
ThreadPool.QueueUserWorkItem (new WaitCallback (worker.Run));
Socket.Select (wSockets, null, null, 500 * 1000); // 500ms
w = wSockets.Count;
for (int i = 0; i < w; i++) {
Socket s = (Socket) wSockets [i];
if (s == listen_socket) {
client = s.Accept ();
WebTrace.WriteLine ("Accepted connection.");
SetSocketOptions (client);
allSockets.Add (client);
timeouts [client] = 0;
continue;
}
allSockets.Remove (s);
timeouts.Remove (s);
IWorker worker = webSource.CreateWorker (s, this);
ThreadPool.QueueUserWorkItem (new WaitCallback (worker.Run));
}
w = timeouts.Count;
Socket [] socks_timeout = new Socket [w];
timeouts.Keys.CopyTo (socks_timeout, 0);
foreach (Socket k in socks_timeout) {
int n = (int) timeouts [k];
if (n >= 30) {
k.Close ();
allSockets.Remove (k);
timeouts.Remove (k);
continue;
}
timeouts [k] = ++n;
}
wSockets.Clear ();
wSockets.AddRange (allSockets);
}
started = false;

Просмотреть файл

@ -9,6 +9,7 @@
//
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
@ -213,8 +214,10 @@ namespace Mono.ASPNET
} catch (Exception e) {
Console.WriteLine (e);
try {
byte [] error = HttpErrors.ServerError ();
stream.Write (error, 0, error.Length);
if (!(e is IOException)) {
byte [] error = HttpErrors.ServerError ();
stream.Write (error, 0, error.Length);
}
stream.Close ();
} catch {}
} finally {

Просмотреть файл

@ -217,8 +217,10 @@ namespace Mono.ASPNET
string value = line.Substring (colon + 1).Trim ();
headers [key] = value;
}
} catch (IOException ioe) {
throw;
} catch (Exception e) {
throw new Exception ("Error reading headers.");
throw new Exception ("Error reading headers.", e);
}
}