frontend_net: initialize m_http_req_max
[metaproxy-moved-to-github.git] / src / filter_frontend_net.cpp
index 6607a1e..3fe5367 100644 (file)
@@ -18,6 +18,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "config.hpp"
 
+#if HAVE_GETRLIMIT
+#include <sys/resource.h>
+#endif
 #include <sstream>
 #include <iomanip>
 #include <metaproxy/util.hpp>
@@ -55,6 +58,8 @@ namespace metaproxy_1 {
             friend class FrontendNet;
 
             int m_no_threads;
+            int m_max_threads;
+            int m_stack_size;
             std::vector<Port> m_ports;
             int m_listen_duration;
             int m_session_timeout;
@@ -524,10 +529,12 @@ yf::FrontendNet::FrontendNet() : m_p(new Rep)
 
 yf::FrontendNet::Rep::Rep()
 {
-    m_no_threads = 5;
+    m_max_threads = m_no_threads = 5;
+    m_stack_size = 0;
     m_listen_duration = 0;
     m_session_timeout = 300; // 5 minutes
     m_connect_max = 0;
+    m_http_req_max = 0;
     az = 0;
     size_t i;
     for (i = 0; i < 22; i++)
@@ -582,6 +589,16 @@ void yf::FrontendNet::stop(int signo) const
     m_p->m_stop_signo = signo;
 }
 
+void yf::FrontendNet::start() const
+{
+#if HAVE_GETRLIMIT
+    struct rlimit limit_data;
+    getrlimit(RLIMIT_NOFILE, &limit_data);
+    yaz_log(YLOG_LOG, "getrlimit NOFILE cur=%ld max=%ld",
+            (long) limit_data.rlim_cur, (long) limit_data.rlim_max);
+#endif
+}
+
 bool yf::FrontendNet::My_Timer_Thread::timeout()
 {
     return m_timeout;
@@ -614,7 +631,9 @@ 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,
+                                m_p->m_stack_size);
 
     for (i = 0; i<m_p->m_ports.size(); i++)
     {
@@ -703,6 +722,24 @@ 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 max-threads: "
+                                                   + threads_str);
+            m_p->m_max_threads = threads;
+        }
+        else if (!strcmp((const char *) ptr->name, "stack-size"))
+        {
+            std::string sz_str = mp::xml::get_text(ptr);
+            int sz = atoi(sz_str.c_str());
+            if (sz < 0)
+                throw yf::FilterException("Bad value for stack-size: "
+                                                   + sz_str);
+            m_p->m_stack_size = sz * 1024;
+        }
         else if (!strcmp((const char *) ptr->name, "timeout"))
         {
             std::string timeout_str = mp::xml::get_text(ptr);