Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Commit

Permalink
2008-01-30 Robert Jordan <robertj@gmx.net>
Browse files Browse the repository at this point in the history
	* src/Mono.WebServer.FastCgi/main.cs (Main):
	Replace Console.WriteLines with Logger.Write. Always log to
	console during Main (). Handle UnmagedSocket's exceptions gracefully.
	Fixes #350779.


svn path=/trunk/xsp/; revision=94406
  • Loading branch information
robert-j committed Jan 30, 2008
1 parent d8fdc79 commit c1d0265
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -1,3 +1,10 @@
2008-01-30 Robert Jordan <robertj@gmx.net>

* src/Mono.WebServer.FastCgi/main.cs (Main):
Replace Console.WriteLines with Logger.Write. Always log to
console during Main (). Handle UnmagedSocket's exceptions gracefully.
Fixes #350779.

2008-01-28 Wade Berrier <wberrier@novell.com>

* configure.in: version bump -> 1.9
Expand Down
74 changes: 39 additions & 35 deletions src/Mono.WebServer.FastCgi/main.cs
Expand Up @@ -145,6 +145,9 @@ public static int Main (string [] args)
Console.WriteLine ("Using default levels: {0}",
Logger.Level);
}

// Enable console logging during Main ().
Logger.WriteToConsole = true;

try {
string log_file = (string)
Expand All @@ -153,17 +156,17 @@ public static int Main (string [] args)
if (log_file != null)
Logger.Open (log_file);
} catch (Exception e) {
Console.WriteLine ("Error opening log file: {0}",
e.Message);
Console.WriteLine ("Events will not be logged.");
Logger.Write (LogLevel.Error,
"Error opening log file: {0}",
e.Message);
Logger.Write (LogLevel.Error,
"Events will not be logged.");
}

Logger.WriteToConsole = (bool) configmanager ["printlog"];

// Send the trace to the console.
Trace.Listeners.Add (
new TextWriterTraceListener (Console.Out));
Console.WriteLine (
Logger.Write (LogLevel.Debug,
Assembly.GetExecutingAssembly ().GetName ().Name);


Expand All @@ -185,9 +188,13 @@ public static int Main (string [] args)
socket = SocketFactory.CreatePipeSocket (
IntPtr.Zero);
} catch (System.Net.Sockets.SocketException){
Console.WriteLine (
Logger.Write (LogLevel.Error,
"Error: Pipe socket is not bound.");
return 1;
} catch (System.NotSupportedException) {
Logger.Write (LogLevel.Error,
"Error: Pipe sockets are not supported on this system.");
return 1;
}
break;

Expand All @@ -205,14 +212,14 @@ public static int Main (string [] args)
socket = SocketFactory.CreateUnixSocket (
path);
} catch (System.Net.Sockets.SocketException e){
Console.WriteLine (
Logger.Write (LogLevel.Error,
"Error creating the socket: {0}",
e.Message);
return 1;
}

Console.WriteLine ("Listening on file: {0}",
path);
Logger.Write (LogLevel.Debug,
"Listening on file: {0}", path);
break;

// The TCP socket is of the format
Expand All @@ -230,7 +237,7 @@ public static int Main (string [] args)
try {
port = (ushort) configmanager ["port"];
} catch (ApplicationException e) {
Console.WriteLine (e.Message);
Logger.Write (LogLevel.Error, e.Message);
return 1;
}

Expand All @@ -241,7 +248,7 @@ public static int Main (string [] args)
try {
address = IPAddress.Parse (address_str);
} catch {
Console.WriteLine (
Logger.Write (LogLevel.Error,
"Error in argument \"address\". \"{0}\" cannot be converted to an IP address.",
address_str);
return 1;
Expand All @@ -251,20 +258,20 @@ public static int Main (string [] args)
socket = SocketFactory.CreateTcpSocket (
address, port);
} catch (System.Net.Sockets.SocketException e){
Console.WriteLine (
Logger.Write (LogLevel.Error,
"Error creating the socket: {0}",
e.Message);
return 1;
}

Console.WriteLine ("Listening on port: {0}",
address_str);
Console.WriteLine ("Listening on address: {0}",
port);
Logger.Write (LogLevel.Debug,
"Listening on port: {0}", address_str);
Logger.Write (LogLevel.Debug,
"Listening on address: {0}", port);
break;

default:
Console.WriteLine (
Logger.Write (LogLevel.Error,
"Error in argument \"socket\". \"{0}\" is not a supported type. Use \"pipe\", \"tcp\" or \"unix\".",
socket_parts [0]);
return 1;
Expand All @@ -275,8 +282,8 @@ public static int Main (string [] args)
try {
Environment.CurrentDirectory = root_dir;
} catch (Exception e) {
Console.WriteLine ("Error: {0}",
e.Message);
Logger.Write (LogLevel.Error,
"Error: {0}", e.Message);
return 1;
}
}
Expand All @@ -298,7 +305,7 @@ public static int Main (string [] args)
app_config_dir = (string)
configmanager ["appconfigdir"];
} catch (ApplicationException e) {
Console.WriteLine (e.Message);
Logger.Write (LogLevel.Error, e.Message);
return 1;
}

Expand All @@ -316,18 +323,18 @@ public static int Main (string [] args)

if (applications == null && app_config_dir == null &&
app_config_file == null && !auto_map) {
Console.WriteLine (
Logger.Write (LogLevel.Error,
"There are no applications defined, and path mapping is disabled.");
Console.WriteLine (
Logger.Write (LogLevel.Error,
"Define an application using /applications, /appconfigfile, /appconfigdir");
/*
Console.WriteLine (
Logger.Write (LogLevel.Error,
"or by enabling application mapping with /automappaths=True.");
*/
return 1;
}

Console.WriteLine ("Root directory: {0}", root_dir);
Logger.Write (LogLevel.Debug, "Root directory: {0}", root_dir);
Mono.FastCgi.Server server = new Mono.FastCgi.Server (
socket);

Expand All @@ -340,18 +347,15 @@ public static int Main (string [] args)
server.MultiplexConnections = (bool)
configmanager ["multiplex"];

Console.WriteLine ("Max connections: {0}",
server.MaxConnections);
Console.WriteLine ("Max requests: {0}",
server.MaxRequests);
Console.WriteLine ("Multiplex connections: {0}",
server.MultiplexConnections);
Logger.Write (LogLevel.Debug, "Max connections: {0}",
server.MaxConnections);
Logger.Write (LogLevel.Debug, "Max requests: {0}",
server.MaxRequests);
Logger.Write (LogLevel.Debug, "Multiplex connections: {0}",
server.MultiplexConnections);

bool stopable = (bool) configmanager ["stopable"];
if (!stopable)
Console.WriteLine (
"Use /stopable=True to enable stopping from the console.");

Logger.WriteToConsole = (bool) configmanager ["printlog"];
server.Start (stopable);

configmanager = null;
Expand Down

0 comments on commit c1d0265

Please sign in to comment.