Beispiel #1
0
/*
 * Poll all queues...
 * a thread, expected to be started from the TASKQ.  Note you must
 * re-register processors once this task exits.
 *
 * Note we expect sender_xml to have QueueInfo embedded!
 */
int qpoller_task (void *parm)
{
  int i,
      poll_interval,
      num_queues;
  QPOLLER *p;
  QPOLLERJOB *j;
  TASKQ *q;
  XML *xml = (XML *) parm;

  info ("Queue Poller starting\n");
  num_queues = xml_count (xml, QP_QUEUE);
  if ((poll_interval = xml_get_int (xml, QP_INFO".PollInterval")) < 1)
    poll_interval = 5;
  poll_interval *= 1000;
  if ((i = xml_get_int (xml, QP_INFO".MaxThreads")) < 1)
    i = 1;
  q = task_allocq (i, poll_interval);
  debug ("%d queues %d interval\n", num_queues, poll_interval);
  while (phineas_running ())
  {
    for (i = 0; i < num_queues; i++)
    {
      qpoller_poll (xml, i, q);
    }
    sleep (poll_interval);
  }
  debug ("Queue Poller shutting down...\n");
  task_stop (q);
  task_freeq (q);
  while ((j = QpollerJobs) != NULL)
  {
    QpollerJobs = j->next;
    free (j);
  }
  while ((p = Qpoller) != NULL)
  {
    Qpoller = p->next;
    free (p);
  }
  info ("Queue Poller exiting\n");
  return (0);
}
Beispiel #2
0
/*
 * Listen for incoming connections until told to stop
 */
int server_listen (XML *xml, NETCON *conn, NETCON *ssl, SSL_CTX *ctx,
  int threads)
{
  char *ch;
  TASKQ *t;
  struct timeval timeout;
  fd_set fds;

  if ((conn == NULL) && (ssl == NULL))
    return (-1);

  t = task_allocq (threads, 2);
  timeout.tv_sec = 2;
  timeout.tv_usec = 0;

  /*
   * Keep servicing requests until they stop coming in AND we are
   * no longer running.  This insures a nice shutdown, although a
   * naughty client could keep us from shutting down by flooding us
   * with requests.  We could add a counter here to prevent that.
   */
  while (1)
  {
    FD_ZERO (&fds);
    if (conn != NULL)
      FD_SET (conn->sock, &fds);
    if (ssl != NULL)
      FD_SET (ssl->sock, &fds);
    if (select (2, &fds, NULL, NULL, &timeout) <= 0)
    {
      if (phineas_running ())
        continue;
      break;
    }
    if ((conn != NULL) && FD_ISSET (conn->sock, &fds))
      server_accept (xml, conn, NULL, t);
    if ((ssl != NULL) && FD_ISSET (ssl->sock, &fds))
      server_accept (xml, ssl, ctx, t);
  }
  task_stop (t);
  task_freeq (t);
  return (0);
}