metaproxy  1.21.0
Classes | Public Member Functions | Private Attributes | List of all members
metaproxy_1::filter::FrontendNet Class Reference

#include <filter_frontend_net.hpp>

Inheritance diagram for metaproxy_1::filter::FrontendNet:
Inheritance graph
Collaboration diagram for metaproxy_1::filter::FrontendNet:
Collaboration graph

Classes

class  IP_Pattern
 
class  My_Timer_Thread
 
class  PeerStat
 
class  Port
 
class  Rep
 
class  ThreadPoolPackage
 
class  ZAssocChild
 
class  ZAssocServer
 

Public Member Functions

 FrontendNet ()
 
 ~FrontendNet ()
 
void process (metaproxy_1::Package &package) const
 
void configure (const xmlNode *ptr, bool test_only, const char *path)
 
void start () const
 
void stop (int signo) const
 
void set_ports (std::vector< Port > &ports)
 set ports More...
 
void set_ports (std::vector< std::string > &ports)
 
void set_listen_duration (int d)
 

Private Attributes

boost::scoped_ptr< Repm_p
 

Detailed Description

Definition at line 31 of file filter_frontend_net.hpp.

Constructor & Destructor Documentation

◆ FrontendNet()

mp::filter::FrontendNet::FrontendNet ( )

Definition at line 631 of file filter_frontend_net.cpp.

631  : m_p(new Rep)
632 {
633 }

◆ ~FrontendNet()

mp::filter::FrontendNet::~FrontendNet ( )

Definition at line 685 of file filter_frontend_net.cpp.

686 {
687 }

Member Function Documentation

◆ configure()

void mp::filter::FrontendNet::configure ( const xmlNode *  ptr,
bool  test_only,
const char *  path 
)

Definition at line 788 of file filter_frontend_net.cpp.

790 {
791  if (!ptr || !ptr->children)
792  {
793  throw yf::FilterException("No ports for Frontend");
794  }
795  std::vector<Port> ports;
796  for (ptr = ptr->children; ptr; ptr = ptr->next)
797  {
798  if (ptr->type != XML_ELEMENT_NODE)
799  continue;
800  if (!strcmp((const char *) ptr->name, "port"))
801  {
802  Port port;
803 
804  const char *names[5] = {"route", "max_recv_bytes", "port",
805  "cert_fname", 0};
806  std::string values[4];
807 
808  mp::xml::parse_attr(ptr, names, values);
809  port.route = values[0];
810  if (values[1].length() > 0)
811  port.max_recv_bytes = atoi(values[1].c_str());
812  else
813  port.max_recv_bytes = 0;
814  if (values[2].length() > 0)
815  port.port = values[2];
816  else
817  port.port = mp::xml::get_text(ptr);
818  port.cert_fname = values[3];
819  ports.push_back(port);
820  }
821  else if (!strcmp((const char *) ptr->name, "threads"))
822  {
823  std::string threads_str = mp::xml::get_text(ptr);
824  int threads = atoi(threads_str.c_str());
825  if (threads < 1)
826  throw yf::FilterException("Bad value for threads: "
827  + threads_str);
828  m_p->m_no_threads = threads;
829  }
830  else if (!strcmp((const char *) ptr->name, "max-threads"))
831  {
832  std::string threads_str = mp::xml::get_text(ptr);
833  int threads = atoi(threads_str.c_str());
834  if (threads < 1)
835  throw yf::FilterException("Bad value for max-threads: "
836  + threads_str);
837  m_p->m_max_threads = threads;
838  }
839  else if (!strcmp((const char *) ptr->name, "stack-size"))
840  {
841  std::string sz_str = mp::xml::get_text(ptr);
842  int sz = atoi(sz_str.c_str());
843  if (sz < 0)
844  throw yf::FilterException("Bad value for stack-size: "
845  + sz_str);
846  m_p->m_stack_size = sz * 1024;
847  }
848  else if (!strcmp((const char *) ptr->name, "timeout"))
849  {
850  const char *names[3] = {"ip", "verbose", 0};
851  std::string values[2];
852 
853  mp::xml::parse_attr(ptr, names, values);
854  IP_Pattern m;
855  m.value = mp::xml::get_int(ptr, 0);
856  m.pattern = values[0];
857  m.verbose = values[1].length() ? atoi(values[1].c_str()) : 1;
858  m_p->session_timeout.push_back(m);
859  }
860  else if (!strcmp((const char *) ptr->name, "connect-max"))
861  {
862  const char *names[3] = {"ip", "verbose", 0};
863  std::string values[2];
864 
865  mp::xml::parse_attr(ptr, names, values);
866  IP_Pattern m;
867  m.value = mp::xml::get_int(ptr, INT_MAX);
868  m.pattern = values[0];
869  m.verbose = values[1].length() ? atoi(values[1].c_str()) : 1;
870  m_p->connect_max.push_back(m);
871  }
872  else if (!strcmp((const char *) ptr->name, "connect-total"))
873  {
874  const char *names[3] = {"ip", "verbose", 0};
875  std::string values[2];
876 
877  mp::xml::parse_attr(ptr, names, values);
878  IP_Pattern m;
879  m.value = mp::xml::get_int(ptr, INT_MAX);
880  m.pattern = values[0];
881  m.verbose = values[1].length() ? atoi(values[1].c_str()) : 1;
882  m_p->connect_total.push_back(m);
883  }
884  else if (!strcmp((const char *) ptr->name, "http-req-max"))
885  {
886  const char *names[3] = {"ip", "verbose", 0};
887  std::string values[2];
888 
889  mp::xml::parse_attr(ptr, names, values);
890  IP_Pattern m;
891  m.value = mp::xml::get_int(ptr, INT_MAX);
892  m.pattern = values[0];
893  m.verbose = values[1].length() ? atoi(values[1].c_str()) : 1;
894  m_p->http_req_max.push_back(m);
895  }
896  else if (!strcmp((const char *) ptr->name, "message"))
897  {
898  m_p->m_msg_config = mp::xml::get_text(ptr);
899  }
900  else if (!strcmp((const char *) ptr->name, "stat-req"))
901  {
902  m_p->m_stat_req = mp::xml::get_text(ptr);
903  }
904  else
905  {
906  throw yf::FilterException("Bad element "
907  + std::string((const char *)
908  ptr->name));
909  }
910  }
911  if (m_p->m_msg_config.length() > 0 && m_p->m_stat_req.length() == 0)
912  { // allow stats if message is enabled for filter
913  m_p->m_stat_req = "/fn_stat";
914  }
915  if (test_only)
916  return;
917  set_ports(ports);
918 }
void set_ports(std::vector< Port > &ports)
set ports

References metaproxy_1::filter::FrontendNet::Port::cert_fname, m_p, metaproxy_1::filter::FrontendNet::Port::max_recv_bytes, metaproxy_1::filter::FrontendNet::IP_Pattern::pattern, metaproxy_1::filter::FrontendNet::Port::port, metaproxy_1::filter::FrontendNet::Port::route, set_ports(), metaproxy_1::filter::FrontendNet::IP_Pattern::value, and metaproxy_1::filter::FrontendNet::IP_Pattern::verbose.

Here is the call graph for this function:

◆ process()

void mp::filter::FrontendNet::process ( metaproxy_1::Package &  package) const

Definition at line 725 of file filter_frontend_net.cpp.

726 {
727  if (m_p->az == 0)
728  return;
729  size_t i;
730  My_Timer_Thread *tt = 0;
731 
732  if (m_p->m_listen_duration)
733  tt = new My_Timer_Thread(&m_p->mySocketManager,
734  m_p->m_listen_duration);
735 
736  ThreadPoolSocketObserver *tp =
737  new ThreadPoolSocketObserver(&m_p->mySocketManager, m_p->m_no_threads,
738  m_p->m_max_threads,
739  m_p->m_stack_size);
740 
741  for (i = 0; i<m_p->m_ports.size(); i++)
742  {
743  m_p->az[i]->set_package(&package);
744  m_p->az[i]->set_thread_pool(
745  tp);
746  }
747  while (m_p->mySocketManager.processEvent() > 0)
748  {
749  if (m_p->m_stop_signo == SIGTERM)
750  {
751  yaz_log(YLOG_LOG, "metaproxy received SIGTERM");
752  if (m_p->az)
753  {
754  size_t i;
755  for (i = 0; i < m_p->m_ports.size(); i++)
756  {
757  m_p->pdu[i]->shutdown();
758  m_p->az[i]->server("");
759  }
760  yaz_daemon_stop();
761  }
762  return; // do not even attempt to destroy tp or tt
763  }
764 #ifndef WIN32
765  if (m_p->m_stop_signo == SIGUSR1)
766  { /* just stop listeners and cont till all sessions are done*/
767  yaz_log(YLOG_LOG, "metaproxy received SIGUSR1");
768  m_p->m_stop_signo = 0;
769  if (m_p->az)
770  {
771  size_t i;
772  for (i = 0; i < m_p->m_ports.size(); i++)
773  m_p->az[i]->server("");
774  yaz_daemon_stop();
775  }
776  }
777 #endif
778  int no = m_p->mySocketManager.getNumberOfObservers();
779  if (no <= 1)
780  break;
781  if (tt && tt->timeout())
782  break;
783  }
784  delete tp;
785  delete tt;
786 }

References m_p, and metaproxy_1::filter::FrontendNet::My_Timer_Thread::timeout().

Here is the call graph for this function:

◆ set_listen_duration()

void mp::filter::FrontendNet::set_listen_duration ( int  d)

Definition at line 972 of file filter_frontend_net.cpp.

973 {
974  m_p->m_listen_duration = d;
975 }

References m_p.

◆ set_ports() [1/2]

void mp::filter::FrontendNet::set_ports ( std::vector< Port > &  ports)

set ports

Definition at line 937 of file filter_frontend_net.cpp.

938 {
939  m_p->m_ports = ports;
940 
941  m_p->az = new yf::FrontendNet::ZAssocServer *[m_p->m_ports.size()];
942  m_p->pdu = new yazpp_1::PDU_Assoc *[m_p->m_ports.size()];
943 
944  // Create yf::FrontendNet::ZAssocServer for each port
945  size_t i;
946  for (i = 0; i < m_p->m_ports.size(); i++)
947  m_p->az[i] = 0;
948  for (i = 0; i < m_p->m_ports.size(); i++)
949  {
950  // create a PDU assoc object (one per yf::FrontendNet::ZAssocServer)
951  yazpp_1::PDU_Assoc *as = new yazpp_1::PDU_Assoc(&m_p->mySocketManager);
952 
953  if (m_p->m_ports[i].cert_fname.length())
954  as->set_cert_fname(m_p->m_ports[i].cert_fname.c_str());
955  // create ZAssoc with PDU Assoc
956  m_p->pdu[i] = as;
957  m_p->az[i] = new yf::FrontendNet::ZAssocServer(
958  as, &m_p->m_ports[i], m_p.get());
959  if (m_p->az[i]->server(m_p->m_ports[i].port.c_str()))
960  {
961  throw yf::FilterException("Unable to bind to address "
962  + std::string(m_p->m_ports[i].port));
963  }
964  COMSTACK cs = as->get_comstack();
965 
966  if (cs && m_p->m_ports[i].max_recv_bytes)
967  cs_set_max_recv_bytes(cs, m_p->m_ports[i].max_recv_bytes);
968 
969  }
970 }

References m_p.

Referenced by configure(), and set_ports().

◆ set_ports() [2/2]

void mp::filter::FrontendNet::set_ports ( std::vector< std::string > &  ports)

Definition at line 920 of file filter_frontend_net.cpp.

921 {
922  std::vector<Port> nports;
923  size_t i;
924 
925  for (i = 0; i < ports.size(); i++)
926  {
927  Port nport;
928 
929  nport.port = ports[i];
930 
931  nports.push_back(nport);
932  }
933  set_ports(nports);
934 }

References metaproxy_1::filter::FrontendNet::Port::port, and set_ports().

Here is the call graph for this function:

◆ start()

void mp::filter::FrontendNet::start ( ) const

Definition at line 694 of file filter_frontend_net.cpp.

695 {
696 #if HAVE_GETRLIMIT
697  struct rlimit limit_data;
698  getrlimit(RLIMIT_NOFILE, &limit_data);
699  yaz_log(YLOG_LOG, "getrlimit NOFILE cur=%ld max=%ld",
700  (long) limit_data.rlim_cur, (long) limit_data.rlim_max);
701 #endif
702 }

◆ stop()

void mp::filter::FrontendNet::stop ( int  signo) const

Definition at line 689 of file filter_frontend_net.cpp.

690 {
691  m_p->m_stop_signo = signo;
692 }

Member Data Documentation

◆ m_p

boost::scoped_ptr<Rep> metaproxy_1::filter::FrontendNet::m_p
private

The documentation for this class was generated from the following files: