Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">Host to bind to</param>
        /// <param name="port">Port to bind to</param>
        /// <param name="handlers">List of request handlers</param>
        public Server(string host, int port, Dictionary<string,IHttpRequestHandler> handlers)
        {
            this.handlers = handlers;

            // Initialize our thread pool
            threads = new List<Thread>();
            // Todo the pool size should be based on the number of cores available
            // or a configuration option
            pool = new Sprite.ThreadPool(7,Sprite.WaitStrategy.MODERATE);
            taskSet = new Sprite.TaskSet(pool,Sprite.WaitStrategy.MODERATE);

            // We may need to handle a permission issue here with a prompt on windows machines
            this.listener = new HttpListener();
            this.listener.IgnoreWriteExceptions = true;
            string prefix = "http://" + host + ":" + port + "/";
            this.listener.Prefixes.Add(prefix);

            Thread thread = new Thread(new ThreadStart(this.Process));

            threads.Add(thread);
        }
Пример #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">Host to bind to</param>
        /// <param name="port">Port to bind to</param>
        /// <param name="handlers">List of request handlers</param>
        public Server(string host, int port, Dictionary <string, IHttpRequestHandler> handlers)
        {
            this.handlers = handlers;

            // Initialize our thread pool
            threads = new List <Thread>();
            // Todo the pool size should be based on the number of cores available
            // or a configuration option
            pool    = new Sprite.ThreadPool(7, Sprite.WaitStrategy.MODERATE);
            taskSet = new Sprite.TaskSet(pool, Sprite.WaitStrategy.MODERATE);


            // We may need to handle a permission issue here with a prompt on windows machines
            this.listener = new HttpListener();
            this.listener.IgnoreWriteExceptions = true;
            string prefix = "http://" + host + ":" + port + "/";

            this.listener.Prefixes.Add(prefix);

            Thread thread = new Thread(new ThreadStart(this.Process));

            threads.Add(thread);
        }