public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout)
 {
     m_server = pSrv;
     m_WorkerThreadCount = pWorkerThreadCount;
     m_workerThreads = new Thread[m_WorkerThreadCount];
     m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount];
     m_timeOut = pTimeout;
 }
        public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout)
        {
            m_server = pSrv;
            m_WorkerThreadCount = pWorkerThreadCount;
            m_workerThreads = new Thread[m_WorkerThreadCount];
            m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount];
            m_workerThreads = new Thread[m_WorkerThreadCount];

            //startup worker threads
            for (uint i = 0; i < m_WorkerThreadCount; i++)
            {
                m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, pTimeout);
                m_PollServiceWorkerThreads[i].ReQueue += ReQueueEvent;
                
                m_workerThreads[i] = new Thread(m_PollServiceWorkerThreads[i].ThreadStart)
                                            {Name = String.Format("PollServiceWorkerThread{0}", i)};
                m_workerThreads[i].Start();
            }

            //start watcher threads
            m_watcherThread = new Thread(ThreadStart) {Name = "PollServiceWatcherThread"};
            m_watcherThread.Start();
        }
 public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout)
 {
     m_server = pSrv;
     m_WorkerThreadCount = pWorkerThreadCount;
     m_pollTimeout = pTimeout;
 }
        /// <summary>
        ///     Get an HTTPServer on the given port. It will create one if one does not exist
        /// </summary>
        /// <param name="port"></param>
        /// <returns></returns>
        public IHttpServer GetHttpServer(uint port)
        {
            if ((port == m_Port || port == 0) && HttpServer != null)
                return HttpServer;

            bool useHTTPS = m_config.Configs["Network"].GetBoolean("use_https", false);
            IHttpServer server;
            if (m_Servers.TryGetValue(port, out server) && server.Secure == useHTTPS)
                return server;

            string hostName =
                m_config.Configs["Network"].GetString("HostName",
                                                      "http" + (useHTTPS ? "s" : "") + "://" + Utilities.GetExternalIp());
            uint threadCount = m_config.Configs["Network"].GetUInt("HttpThreadCount", 5);
            //Clean it up a bit
            if (hostName.StartsWith("http://") || hostName.StartsWith("https://"))
                hostName = hostName.Replace("https://", "").Replace("http://", "");
            if (hostName.EndsWith("/"))
                hostName = hostName.Remove(hostName.Length - 1, 1);

            server = new BaseHttpServer(port, hostName, useHTTPS, threadCount);

            try
            {
                server.Start();
            }
            catch (Exception)
            {
                //Remove the server from the list
                m_Servers.Remove(port);
                //Then pass the exception upwards
                throw;
            }
            if (m_Servers.Count == 0)
                MainServer.Instance = server;
            return (m_Servers[port] = server);
        }
        public IHttpServer GetHttpServer (uint port, bool secure, string certPath, string certPass, SslProtocols sslProtocol)
        {
            if ((port == m_Port || port == 0) && HttpServer != null)
                return HttpServer;

            BaseHttpServer server;
            if(m_Servers.TryGetValue(port, out server) && server.Secure == secure)
                return server;

            string hostName =
                m_config.Configs["Network"].GetString("HostName", "http" + (secure ? "s" : "") + "://" + Utilities.GetExternalIp());
            //Clean it up a bit
            if (hostName.StartsWith("http://") || hostName.StartsWith("https://"))
                hostName = hostName.Replace("https://", "").Replace("http://", "");
            if (hostName.EndsWith ("/"))
                hostName = hostName.Remove (hostName.Length - 1, 1);

            server = new BaseHttpServer(port, hostName, secure);

            try
            {
                if(secure)//Set these params now
                    server.SetSecureParams(certPath, certPass, sslProtocol);
                server.Start();
            }
            catch(Exception)
            {
                //Remove the server from the list
                m_Servers.Remove (port);
                //Then pass the exception upwards
                throw;
            }

            return (m_Servers[port] = server);
        }
 public void RegionLoaded(IScene scene)
 {
     if (IsEnabled() && !m_httpServerStarted)
     {
         m_httpServerStarted = true;
         // Start http server
         // Attach xmlrpc handlers
         MainConsole.Instance.Info("[XMLRPC MODULE]: " +
                                   "Starting up XMLRPC Server on port " + m_remoteDataPort +
                                   " for llRemoteData commands.");
         IHttpServer httpServer = new BaseHttpServer((uint) m_remoteDataPort, MainServer.Instance.HostName,
                                                     false, 1);
         httpServer.AddXmlRPCHandler("llRemoteData", XmlRpcRemoteData);
         httpServer.Start();
     }
     m_scriptModule = scene.RequestModuleInterface<IScriptModule>();
 }
 public MessageHandler(BaseHttpServer server)
 {
     _server = server;
 }
 public void Dispose()
 {
     _server = null;
 }
 public PollServiceWorkerThread(BaseHttpServer pSrv, int pTimeout)
 {
     m_request = new BlockingQueue<PollServiceHttpRequest>();
     m_server = pSrv;
     m_timeout = pTimeout;
 }
        /// <summary>
        /// FIXME: This should be part of BaseHttpServer
        /// </summary>
        internal static void DoHTTPGruntWork(BaseHttpServer server, PollServiceHttpRequest req, Hashtable responsedata)
        {
            OSHttpResponse response
                = new OSHttpResponse(new HttpResponse(req.HttpContext, req.Request), req.HttpContext);

            byte[] buffer = server.DoHTTPGruntWork(responsedata, response);

            response.SendChunked = false;
            response.ContentLength64 = buffer.Length;
            response.ContentEncoding = Encoding.UTF8;

            try
            {
                response.OutputStream.Write(buffer, 0, buffer.Length);
            }
            catch (Exception ex)
            {
                m_log.Warn(string.Format("[POLL SERVICE WORKER THREAD]: Error ", ex));
            }
            finally
            {
                //response.OutputStream.Close();
                try
                {
                    response.OutputStream.Flush();
                    response.Send();

                    //if (!response.KeepAlive && response.ReuseContext)
                    //    response.FreeContext();
                }
                catch (Exception e)
                {
                    m_log.Warn(String.Format("[POLL SERVICE WORKER THREAD]: Error ", e));
                }
            }
        }