frontend_net: dynamic thread pool MP-629
[metaproxy-moved-to-github.git] / src / filter_frontend_net.cpp
index 6607a1e..3df0332 100644 (file)
@@ -55,6 +55,7 @@ namespace metaproxy_1 {
             friend class FrontendNet;
 
             int m_no_threads;
+            int m_max_threads;
             std::vector<Port> m_ports;
             int m_listen_duration;
             int m_session_timeout;
@@ -524,7 +525,7 @@ yf::FrontendNet::FrontendNet() : m_p(new Rep)
 
 yf::FrontendNet::Rep::Rep()
 {
-    m_no_threads = 5;
+    m_max_threads = m_no_threads = 5;
     m_listen_duration = 0;
     m_session_timeout = 300; // 5 minutes
     m_connect_max = 0;
@@ -614,7 +615,8 @@ void yf::FrontendNet::process(mp::Package &package) const
         tt = new My_Timer_Thread(&m_p->mySocketManager,
                                  m_p->m_listen_duration);
 
-    ThreadPoolSocketObserver tp(&m_p->mySocketManager, m_p->m_no_threads);
+    ThreadPoolSocketObserver tp(&m_p->mySocketManager, m_p->m_no_threads,
+                                m_p->m_max_threads);
 
     for (i = 0; i<m_p->m_ports.size(); i++)
     {
@@ -703,6 +705,15 @@ void yf::FrontendNet::configure(const xmlNode * ptr, bool test_only,
                                                    + threads_str);
             m_p->m_no_threads = threads;
         }
+        else if (!strcmp((const char *) ptr->name, "max-threads"))
+        {
+            std::string threads_str = mp::xml::get_text(ptr);
+            int threads = atoi(threads_str.c_str());
+            if (threads < 1)
+                throw yf::FilterException("Bad value for threads: "
+                                                   + threads_str);
+            m_p->m_max_threads = threads;
+        }
         else if (!strcmp((const char *) ptr->name, "timeout"))
         {
             std::string timeout_str = mp::xml::get_text(ptr);