Author: mhabersack
Date: 2007-12-04 04:08:14 -0500 (Tue, 04 Dec 2007)
New Revision: 90627
Modified:
trunk/xsp/ChangeLog
trunk/xsp/src/Mono.WebServer.XSP/main.cs
trunk/xsp/src/Mono.WebServer/ApplicationServer.cs
trunk/xsp/src/Mono.WebServer/XSPWebSource.cs
Log:
2007-12-04 Marek Habersack <[EMAIL PROTECTED]>
* src/Mono.WebServer/ApplicationServer.cs: added a new property,
Port, to report the actual port ApplicationServer is listening on
* src/Mono.WebServer.XSP/main.cs: accept an extra parameter to
attach XSP to a random port. The actual port is printed to the
console instead of the configured one, as it was done before.
Modified: trunk/xsp/ChangeLog
===================================================================
--- trunk/xsp/ChangeLog 2007-12-04 09:05:21 UTC (rev 90626)
+++ trunk/xsp/ChangeLog 2007-12-04 09:08:14 UTC (rev 90627)
@@ -1,3 +1,12 @@
+2007-12-04 Marek Habersack <[EMAIL PROTECTED]>
+
+ * src/Mono.WebServer/ApplicationServer.cs: added a new property,
+ Port, to report the actual port ApplicationServer is listening on
+
+ * src/Mono.WebServer.XSP/main.cs: accept an extra parameter to
+ attach XSP to a random port. The actual port is printed to the
+ console instead of the configured one, as it was done before.
+
2007-11-21 Marek Habersack <[EMAIL PROTECTED]>
* Added several index.aspx files to avoid 404 errors on accessing
Modified: trunk/xsp/src/Mono.WebServer/ApplicationServer.cs
===================================================================
--- trunk/xsp/src/Mono.WebServer/ApplicationServer.cs 2007-12-04 09:05:21 UTC
(rev 90626)
+++ trunk/xsp/src/Mono.WebServer/ApplicationServer.cs 2007-12-04 09:08:14 UTC
(rev 90627)
@@ -93,6 +93,23 @@
// This is much faster than hashtable for typical cases.
ArrayList vpathToHost = new ArrayList ();
+
+ public int Port {
+ get {
+ if (listen_socket == null
+#if NET_2_0
+ || !listen_socket.IsBound
+#endif
+ )
+ return -1;
+
+ IPEndPoint iep = listen_socket.LocalEndPoint as
IPEndPoint;
+ if (iep == null)
+ return -1;
+
+ return iep.Port;
+ }
+ }
public ApplicationServer (WebSource source)
{
Modified: trunk/xsp/src/Mono.WebServer/XSPWebSource.cs
===================================================================
--- trunk/xsp/src/Mono.WebServer/XSPWebSource.cs 2007-12-04 09:05:21 UTC
(rev 90626)
+++ trunk/xsp/src/Mono.WebServer/XSPWebSource.cs 2007-12-04 09:08:14 UTC
(rev 90627)
@@ -58,8 +58,8 @@
bool requireClientCert;
public XSPWebSource(IPAddress address, int port,
SecurityProtocolType securityProtocol,
- X509Certificate cert,
PrivateKeySelectionCallback keyCB,
- bool allowClientCert, bool
requireClientCert)
+ X509Certificate cert,
PrivateKeySelectionCallback keyCB,
+ bool allowClientCert, bool
requireClientCert)
{
secureConnection = (cert != null && keyCB != null);
this.bindAddress = new IPEndPoint (address, port);
Modified: trunk/xsp/src/Mono.WebServer.XSP/main.cs
===================================================================
--- trunk/xsp/src/Mono.WebServer.XSP/main.cs 2007-12-04 09:05:21 UTC (rev
90626)
+++ trunk/xsp/src/Mono.WebServer.XSP/main.cs 2007-12-04 09:08:14 UTC (rev
90627)
@@ -59,7 +59,7 @@
Console.WriteLine ("{0} {1}\n(c) {2}\n{3}",
Path.GetFileName (assembly.Location),
version, copyright, description);
}
-
+
static void ShowHelp ()
{
Console.WriteLine ("XSP server is a sample server that
hosts the ASP.NET runtime in a");
@@ -70,6 +70,8 @@
Console.WriteLine (" --port N: n is the tcp port to
listen on.");
Console.WriteLine (" Default value:
8080");
Console.WriteLine (" AppSettings key
name: MonoServerPort");
+ Console.WriteLine (" --random-port: listen on a
randomly assigned port. The port numer");
+ Console.WriteLine (" will be
reported to the caller via a text file.");
Console.WriteLine ();
Console.WriteLine (" --address addr: addr is the ip
address to listen on.");
Console.WriteLine (" Default value:
0.0.0.0");
@@ -164,7 +166,8 @@
Port = 1 << 8,
Terminate = 1 << 9,
Https = 1 << 10,
- Master = 1 << 11
+ Master = 1 << 11,
+ RandomPort = 1 << 12
}
static void CheckAndSetOptions (string name, Options value, ref
Options options)
@@ -184,6 +187,11 @@
Console.WriteLine ("ERROR: --port/--address and
--filename are mutually exclusive");
Environment.Exit (1);
}
+
+ if ((options & Options.Port) != 0 && value ==
Options.RandomPort) {
+ Console.WriteLine ("ERROR: --port and
--random-port are mutually exclusive");
+ Environment.Exit (1);
+ }
}
static AsymmetricAlgorithm GetPrivateKey (X509Certificate
certificate, string targetHost)
@@ -225,8 +233,8 @@
object oport;
string ip = AppSettings ["MonoServerAddress"];
bool master = false;
-
- if (ip == "" || ip == null)
+
+ if (ip == null || ip.Length == 0)
ip = "0.0.0.0";
oport = AppSettings ["MonoServerPort"];
@@ -276,6 +284,10 @@
CheckAndSetOptions (a, Options.Port,
ref options);
oport = args [++i];
break;
+ case "--random-port":
+ CheckAndSetOptions (a,
Options.RandomPort, ref options);
+ oport = 0;
+ break;
case "--address":
CheckAndSetOptions (a, Options.Address,
ref options);
ip = args [++i];
@@ -318,6 +330,7 @@
IPAddress ipaddr = null;
ushort port;
try {
+
port = Convert.ToUInt16 (oport);
} catch (Exception) {
Console.WriteLine ("The value given for the
listen port is not valid: " + oport);
@@ -374,15 +387,17 @@
if (!master && apps == null && appConfigDir == null &&
appConfigFile == null)
server.AddApplicationsFromCommandLine ("/:.");
- Console.WriteLine ("Listening on port: {0}
{1}", port, security);
- Console.WriteLine ("Listening on address: {0}",
ip);
-
+ Console.WriteLine ("Listening on address: {0}", ip);
Console.WriteLine ("Root directory: {0}", rootDir);
try {
if (server.Start (!nonstop) == false)
return 2;
-
+
+ Console.WriteLine ("Listening on port: {0}
{1}", server.Port, security);
+ if (port == 0)
+ Console.Error.WriteLine ("Random port:
{0}", server.Port);
+
if (!nonstop) {
Console.WriteLine ("Hit Return to stop
the server.");
Console.ReadLine ();
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches