Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="config">Web Server configuration</param>
        public MicroWebServer(MicroWebServerConfig config)
        {
            // check HTTP port
            if (config.HttpPort <= 0)
            {
                throw new ArgumentException("Wrong HTTP port in configuration");
            }

            // check backlog
            if (config.Backlog <= 0)
            {
                throw new ArgumentException("Wrong Backlog in configuration");
            }

            // if not defined, set WebRoot default directory
            if ((config.WebRoot == null) || (config.WebRoot == String.Empty))
            {
                this.config.WebRoot = WEBROOT_DEFAULT;
            }

            // set Web Server configuration
            this.config = config;

            // create Web Root directory if it doesn't exist
            if (!Directory.Exists(this.config.WebRoot))
            {
                Directory.CreateDirectory(this.config.WebRoot);
            }

            // listener thread not yet running
            this.isRunning = false;
            // create thread pool for request processing and request queue
            this.workerThreadPool = new ArrayList();
            this.requestQueue     = new Queue();

            // create handlers collection and set defaults handler
            this.handlers          = new Hashtable();
            this.fileSystemHandler = new FileSystemHandler();
            this.cgiHandler        = new CgiHandler();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="config">Web Server configuration</param>
        public MicroWebServer(MicroWebServerConfig config)
        {
            // check HTTP port
            if (config.HttpPort <= 0)
                throw new ArgumentException("Wrong HTTP port in configuration");

            // check backlog
            if (config.Backlog <= 0)
                throw new ArgumentException("Wrong Backlog in configuration");

            // if not defined, set WebRoot default directory
            if ((config.WebRoot == null) || (config.WebRoot == String.Empty))
                this.config.WebRoot = WEBROOT_DEFAULT;

            // set Web Server configuration
            this.config = config;

            // create Web Root directory if it doesn't exist
            if (!Directory.Exists(this.config.WebRoot))
                Directory.CreateDirectory(this.config.WebRoot);

            // listener thread not yet running
            this.isRunning = false;
            // create thread pool for request processing and request queue
            this.workerThreadPool = new ArrayList();
            this.requestQueue = new Queue();

            // create handlers collection and set defaults handler
            this.handlers = new Hashtable();
            this.fileSystemHandler = new FileSystemHandler();
            this.cgiHandler = new CgiHandler();
        }
 /// <summary>
 /// Register the callback for builtin CGI handler
 /// </summary>
 /// <param name="cgiCallback">Callback for CGI request</param>
 public void RegisterCgiCallback(CgiHandler.ProcessGgiRequestDelegate cgiCallback)
 {
     this.cgiHandler.CgiCallback = cgiCallback;
 }