Esempio n. 1
0
        public OnDemandServer(Socket socket)
        {
            backend = new GenericServer <ConnectionProxy> (socket, this);
            var fakeBackend = new FakeGenericServer <ConnectionProxy> (backend);

            server = new Mono.FastCgi.Server(fakeBackend);
        }
Esempio n. 2
0
        public static void Initialize()
        {
            try
            {
                // Create socket, and start listing for FastCGI connections.
                Socket socket;
                socket = SocketFactory.CreatePipeSocket (IntPtr.Zero);
            //				Socket = SocketFactory.CreatePipeSocket (IntPtr.Zero);

                // Create server
                Server = new Mono.FastCgi.Server (socket);
            //				Server = new Mono.FastCgi.Server (Socket);
                Server.SetResponder (typeof (SorentoLib.FastCgi.Responder));

                // Configure server
            //				Server.MaxConnections = Services.Config.Get<int> (Enums.ConfigKey.fastcgi_maxconnections);
            //				Server.MaxRequests = Services.Config.Get<int> (Enums.ConfigKey.fastcgi_maxrequests);
                Server.MaxConnections = 50;
                Server.MaxRequests = 50;
                Server.MultiplexConnections = false;
            //				Server.MultiplexConnections = Services.Config.Get<bool> (Enums.ConfigKey.fastcgi_multiplexconnections);

                // Start listing.
                Server.Start (false);
            }
            catch
            {
                Services.Logging.LogFatalError (Strings.LogErrorFatal.FastCGIFailedToStartServer);
                Shutdown ();
            }

            // LOG: LogInfo.RuntimeServiceInitialized
            Services.Logging.LogInfo (string.Format (Strings.LogInfo.RuntimeServiceInitialized, "FastCGI"));
        }
Esempio n. 3
0
 public Connection(Socket socket, Server server)
 {
     this.socket = socket;
     this.server = server;
     server.AllocateBuffers (out receive_buffer,
         out send_buffer);
 }
Esempio n. 4
0
 internal ServerProxy(Mono.FastCgi.Server server)
 {
     if (server == null)
     {
         throw new ArgumentNullException("server");
     }
     this.server = server;
 }
Esempio n. 5
0
        public Connection(Socket socket, Server server)
        {
            if (socket == null)
                throw new ArgumentNullException ("socket");
            if (server == null)
                throw new ArgumentNullException ("server");

            this.socket = socket;
            this.server = server;
            server.AllocateBuffers (out receive_buffer, out send_buffer);
        }
Esempio n. 6
0
        public OnDemandServer(Socket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            backend = new GenericServer <ConnectionProxy> (socket, this);
            var fakeBackend = new FakeGenericServer <ConnectionProxy> (backend);

            server = new Mono.FastCgi.Server(fakeBackend);
        }
Esempio n. 7
0
        static Mono.FastCgi.Server CreateServer(ConfigurationManager configurationManager,
                                                Socket socket)
        {
            var server = new Mono.FastCgi.Server(socket)
            {
                MaxConnections       = configurationManager.MaxConns,
                MaxRequests          = configurationManager.MaxReqs,
                MultiplexConnections = configurationManager.Multiplex
            };

            server.SetResponder(typeof(Responder));

            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);
            return(server);
        }
Esempio n. 8
0
        public static int Main(string [] args)
        {
            // Load the configuration file stored in the
            // executable's resources.
            configmanager = new ConfigurationManager(
                typeof(Server).Assembly,
                "ConfigurationManager.xml");

            configmanager.LoadCommandLineArgs(args);

            // Show the help and exit.
            if ((bool)configmanager ["help"] ||
                (bool)configmanager ["?"])
            {
                ShowHelp();
                return(0);
            }

            // Show the version and exit.
            if ((bool)configmanager ["version"])
            {
                ShowVersion();
                return(0);
            }

            try {
                string config_file = (string)
                                     configmanager ["configfile"];
                if (config_file != null)
                {
                    configmanager.LoadXmlConfig(
                        config_file);
                }
            } catch (ApplicationException e) {
                Console.WriteLine(e.Message);
                return(1);
            } catch (System.Xml.XmlException e) {
                Console.WriteLine(
                    "Error reading XML configuration: {0}",
                    e.Message);
                return(1);
            }

            try {
                string log_level = (string)
                                   configmanager ["loglevels"];

                if (log_level != null)
                {
                    Logger.Level = (LogLevel)
                                   Enum.Parse(typeof(LogLevel),
                                              log_level);
                }
            } catch {
                Console.WriteLine("Failed to parse log levels.");
                Console.WriteLine("Using default levels: {0}",
                                  Logger.Level);
            }

            try {
                string log_file = (string)
                                  configmanager ["logfile"];

                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.WriteToConsole = (bool)configmanager ["printlog"];

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


            // Create the socket.
            Socket socket;

            // Socket strings are in the format
            // "type[:ARG1[:ARG2[:...]]]".
            string socket_type = configmanager ["socket"] as string;

            if (socket_type == null)
            {
                socket_type = "pipe";
            }

            string [] socket_parts = socket_type.Split(
                new char [] { ':' }, 3);

            switch (socket_parts [0].ToLower())
            {
            case "pipe":
                try {
                    socket = SocketFactory.CreatePipeSocket(
                        IntPtr.Zero);
                } catch (System.Net.Sockets.SocketException) {
                    Console.WriteLine(
                        "Error: Pipe socket is not bound.");
                    return(1);
                }
                break;

            // The FILE sockets is of the format
            // "file[:PATH]".
            case "unix":
            case "file":
                if (socket_parts.Length == 2)
                {
                    configmanager ["filename"] =
                        socket_parts [1];
                }

                string path = (string)configmanager ["filename"];

                try {
                    socket = SocketFactory.CreateUnixSocket(
                        path);
                } catch (System.Net.Sockets.SocketException e) {
                    Console.WriteLine(
                        "Error creating the socket: {0}",
                        e.Message);
                    return(1);
                }

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

            // The TCP socket is of the format
            // "tcp[[:ADDRESS]:PORT]".
            case "tcp":
                if (socket_parts.Length > 1)
                {
                    configmanager ["port"] = socket_parts [
                        socket_parts.Length - 1];
                }

                if (socket_parts.Length == 3)
                {
                    configmanager ["address"] =
                        socket_parts [1];
                }

                ushort port;
                try {
                    port = (ushort)configmanager ["port"];
                } catch (ApplicationException e) {
                    Console.WriteLine(e.Message);
                    return(1);
                }

                string address_str =
                    (string)configmanager ["address"];
                IPAddress address;

                try {
                    address = IPAddress.Parse(address_str);
                } catch {
                    Console.WriteLine(
                        "Error in argument \"address\". \"{0}\" cannot be converted to an IP address.",
                        address_str);
                    return(1);
                }

                try {
                    socket = SocketFactory.CreateTcpSocket(
                        address, port);
                } catch (System.Net.Sockets.SocketException e) {
                    Console.WriteLine(
                        "Error creating the socket: {0}",
                        e.Message);
                    return(1);
                }

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

            default:
                Console.WriteLine(
                    "Error in argument \"socket\". \"{0}\" is not a supported type. Use \"pipe\", \"tcp\" or \"unix\".",
                    socket_parts [0]);
                return(1);
            }

            string root_dir = configmanager ["root"] as string;

            if (root_dir != null && root_dir.Length != 0)
            {
                try {
                    Environment.CurrentDirectory = root_dir;
                } catch (Exception e) {
                    Console.WriteLine("Error: {0}",
                                      e.Message);
                    return(1);
                }
            }

            root_dir = Environment.CurrentDirectory;
            bool auto_map = (bool)configmanager ["automappaths"];

            appmanager = new ApplicationManager(
                typeof(ApplicationHost), auto_map, false);
            appmanager.Verbose = (bool)configmanager ["verbose"];

            string applications = (string)
                                  configmanager ["applications"];
            string app_config_file;
            string app_config_dir;

            try {
                app_config_file = (string)
                                  configmanager ["appconfigfile"];
                app_config_dir = (string)
                                 configmanager ["appconfigdir"];
            } catch (ApplicationException e) {
                Console.WriteLine(e.Message);
                return(1);
            }

            if (applications != null)
            {
                appmanager.AddApplicationsFromCommandLine(
                    applications);
            }

            if (app_config_file != null)
            {
                appmanager.AddApplicationsFromConfigFile(
                    app_config_file);
            }

            if (app_config_dir != null)
            {
                appmanager.AddApplicationsFromConfigDirectory(
                    app_config_dir);
            }

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

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

            server.SetResponder(typeof(Responder));

            server.MaxConnections = (ushort)
                                    configmanager ["maxconns"];
            server.MaxRequests = (ushort)
                                 configmanager ["maxreqs"];
            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);

            bool stopable = (bool)configmanager ["stopable"];

            if (!stopable)
            {
                Console.WriteLine(
                    "Use /stopable=True to enable stopping from the console.");
            }

            server.Start(stopable);

            configmanager = null;

            if (stopable)
            {
                Console.WriteLine(
                    "Hit Return to stop the server.");
                Console.ReadLine();
                server.Stop();
            }

            return(0);
        }
        static Mono.FastCgi.Server CreateServer(ConfigurationManager configurationManager,
		                                         Socket socket)
        {
            var server = new Mono.FastCgi.Server (socket) {
                MaxConnections = configurationManager.MaxConns,
                MaxRequests = configurationManager.MaxReqs,
                MultiplexConnections = configurationManager.Multiplex
            };

            server.SetResponder (typeof(Responder));

            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);
            return server;
        }
Esempio n. 10
0
		public static int Main (string [] args)
		{
			// Load the configuration file stored in the
			// executable's resources.
			configmanager = new ConfigurationManager (
				typeof (Server).Assembly,
				"ConfigurationManager.xml");
			
			configmanager.LoadCommandLineArgs (args);
			
			// Show the help and exit.
			if ((bool) configmanager ["help"] ||
				(bool) configmanager ["?"]) {
				ShowHelp ();
				return 0;
			}
			
			// Show the version and exit.
			if ((bool) configmanager ["version"]) {
				ShowVersion ();
				return 0;
			}
			
			try {
				string config_file = (string)
					configmanager ["configfile"];
				if (config_file != null)
					configmanager.LoadXmlConfig (
						config_file);
			} catch (ApplicationException e) {
				Console.WriteLine (e.Message);
				return 1;
			} catch (System.Xml.XmlException e) {
				Console.WriteLine (
					"Error reading XML configuration: {0}",
					e.Message);
				return 1;
			}
			
			try {
				string log_level = (string)
					configmanager ["loglevels"];
				
				if (log_level != null)
					Logger.Level = (LogLevel)
						Enum.Parse (typeof (LogLevel),
							log_level);
			} catch {
				Console.WriteLine ("Failed to parse log levels.");
				Console.WriteLine ("Using default levels: {0}",
					Logger.Level);
			}
			
			try {
				string log_file = (string)
					configmanager ["logfile"];
				
				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.WriteToConsole = (bool) configmanager ["printlog"];

			// Send the trace to the console.
			Trace.Listeners.Add (
				new TextWriterTraceListener (Console.Out));
			Console.WriteLine (
				Assembly.GetExecutingAssembly ().GetName ().Name);
			
			
			// Create the socket.
			Socket socket;
			
			// Socket strings are in the format
			// "type[:ARG1[:ARG2[:...]]]".
			string socket_type = configmanager ["socket"] as string;
			if (socket_type == null)
				socket_type = "pipe";
			
			string [] socket_parts = socket_type.Split (
				new char [] {':'}, 3);
			
			switch (socket_parts [0].ToLower ()) {
			case "pipe":
				try {
					socket = SocketFactory.CreatePipeSocket (
						IntPtr.Zero);
				} catch (System.Net.Sockets.SocketException){
					Console.WriteLine (
						"Error: Pipe socket is not bound.");
					return 1;
				}
				break;
			
			// The FILE sockets is of the format
			// "file[:PATH]".
			case "unix":
			case "file":
				if (socket_parts.Length == 2)
					configmanager ["filename"] =
						socket_parts [1];
				
				string path = (string) configmanager ["filename"];
				
				try {
					socket = SocketFactory.CreateUnixSocket (
						path);
				} catch (System.Net.Sockets.SocketException e){
					Console.WriteLine (
						"Error creating the socket: {0}",
						e.Message);
					return 1;
				}
				
				Console.WriteLine ("Listening on file: {0}",
					path);
				break;
			
			// The TCP socket is of the format
			// "tcp[[:ADDRESS]:PORT]".
			case "tcp":
				if (socket_parts.Length > 1)
					configmanager ["port"] = socket_parts [
						socket_parts.Length - 1];
				
				if (socket_parts.Length == 3)
					configmanager ["address"] =
						socket_parts [1];
				
				ushort port;
				try {
					port = (ushort) configmanager ["port"];
				} catch (ApplicationException e) {
					Console.WriteLine (e.Message);
					return 1;
				}
				
				string address_str =
					(string) configmanager ["address"];
				IPAddress address;
				
				try {
					address = IPAddress.Parse (address_str);
				} catch {
					Console.WriteLine (
						"Error in argument \"address\". \"{0}\" cannot be converted to an IP address.",
						address_str);
					return 1;
				}
				
				try {
					socket = SocketFactory.CreateTcpSocket (
						address, port);
				} catch (System.Net.Sockets.SocketException e){
					Console.WriteLine (
						"Error creating the socket: {0}",
						e.Message);
					return 1;
				}
				
				Console.WriteLine ("Listening on port: {0}",
					address_str);
				Console.WriteLine ("Listening on address: {0}",
					port);
				break;
				
			default:
				Console.WriteLine (
					"Error in argument \"socket\". \"{0}\" is not a supported type. Use \"pipe\", \"tcp\" or \"unix\".",
					socket_parts [0]);
				return 1;
			}
			
			string root_dir = configmanager ["root"] as string;
			if (root_dir != null && root_dir.Length != 0) {
				try {
					Environment.CurrentDirectory = root_dir;
				} catch (Exception e) {
					Console.WriteLine ("Error: {0}",
						e.Message);
					return 1;
				}
			}
			
			root_dir = Environment.CurrentDirectory;
			bool auto_map = (bool) configmanager ["automappaths"];
			appmanager = new ApplicationManager (
				typeof (ApplicationHost), auto_map, false);
			appmanager.Verbose = (bool) configmanager ["verbose"];
			
			string applications = (string)
				configmanager ["applications"];
			string app_config_file;
			string app_config_dir;
			
			try {
				app_config_file = (string)
					configmanager ["appconfigfile"];
				app_config_dir = (string)
					configmanager ["appconfigdir"];
			} catch (ApplicationException e) {
				Console.WriteLine (e.Message);
				return 1;
			}
			
			if (applications != null)
				appmanager.AddApplicationsFromCommandLine (
					applications);
			
			if (app_config_file != null)
				appmanager.AddApplicationsFromConfigFile (
					app_config_file);
			
			if (app_config_dir != null)
				appmanager.AddApplicationsFromConfigDirectory (
					app_config_dir);

			if (applications == null && app_config_dir == null &&
				app_config_file == null && !auto_map) {
				Console.WriteLine (
					"There are no applications defined, and path mapping is disabled.");
				Console.WriteLine (
					"Define an application using /applications, /appconfigfile, /appconfigdir");
				Console.WriteLine (
					"or by enabling application mapping with /automappaths=True.");
				return 1;
			}
			
			Console.WriteLine ("Root directory: {0}", root_dir);
			Mono.FastCgi.Server server = new Mono.FastCgi.Server (
				socket);
			
			server.SetResponder (typeof (Responder));
			
			server.MaxConnections = (ushort)
				configmanager ["maxconns"];
			server.MaxRequests = (ushort)
				configmanager ["maxreqs"];
			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);
			
			bool stopable = (bool) configmanager ["stopable"];
			if (!stopable)
				Console.WriteLine (
					"Use /stopable=True to enable stopping from the console.");
			
			server.Start (stopable);
			
			configmanager = null;
			
			if (stopable) {
				Console.WriteLine (
					"Hit Return to stop the server.");
				Console.ReadLine ();
				server.Stop ();
			}
			
			return 0;
		}