Exemplo n.º 1
0
static void *
ServeOneRequest(void *param)
{
  struct MHD_Daemon *d;
  fd_set rs;
  fd_set ws;
  fd_set es;
  MHD_socket fd, max;
  time_t start;
  struct timeval tv;
  int done = 0;

  fd = (MHD_socket) (intptr_t) param;

  d = MHD_start_daemon (MHD_USE_ERROR_LOG,
                        1082, NULL, NULL, &ahc_echo, "GET",
                        MHD_OPTION_LISTEN_SOCKET, fd,
                        MHD_OPTION_NOTIFY_COMPLETED, &request_completed, &done,
                        MHD_OPTION_END);
  if (d == NULL)
    return "MHD_start_daemon() failed";

  start = time (NULL);
  while ((time (NULL) - start < 5) && done == 0)
    {
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
        {
          MHD_stop_daemon (d);
          MHD_socket_close_chk_(fd);
          return "MHD_get_fdset() failed";
        }
      tv.tv_sec = 0;
      tv.tv_usec = 1000;
      if (-1 == MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv))
        {
          if (EINTR != errno)
            abort ();
        }
      MHD_run (d);
    }
  fd = MHD_quiesce_daemon (d);
  if (MHD_INVALID_SOCKET == fd)
    {
      MHD_stop_daemon (d);
      return "MHD_quiesce_daemon() failed in ServeOneRequest()";
    }
  MHD_stop_daemon (d);
  return done ? NULL : "Requests was not served by ServeOneRequest()";
}
Exemplo n.º 2
0
MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_
select_thread(void* data)
{
  /* use select() like in daemon.c */
  MHD_socket listen_sock = *((MHD_socket*)data);
  fd_set rs, ws;
  struct timeval timeout;

  FD_ZERO(&rs);
  FD_ZERO(&ws);
  FD_SET(listen_sock, &rs);
  timeout.tv_usec = 0;
  timeout.tv_sec = 7;

  check_err = (0 > MHD_SYS_select_(listen_sock + 1, &rs, &ws, NULL, &timeout));

  return (MHD_THRD_RTRN_TYPE_)0;
}
Exemplo n.º 3
0
static void *
ServeOneRequest(void *param)
{
    struct MHD_Daemon *d;
    fd_set rs;
    fd_set ws;
    fd_set es;
    MHD_socket fd, max;
    time_t start;
    struct timeval tv;
    int done = 0;

    fd = (MHD_socket) (intptr_t) param;

    d = MHD_start_daemon (MHD_USE_DEBUG,
                          1082, NULL, NULL, &ahc_echo, "GET",
                          MHD_OPTION_LISTEN_SOCKET, fd,
                          MHD_OPTION_NOTIFY_COMPLETED, &request_completed, &done,
                          MHD_OPTION_END);
    if (d == NULL)
        return "MHD_start_daemon() failed";

    start = time (NULL);
    while ((time (NULL) - start < 5) && done == 0)
    {
        max = 0;
        FD_ZERO (&rs);
        FD_ZERO (&ws);
        FD_ZERO (&es);
        if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
        {
            MHD_stop_daemon (d);
            MHD_socket_close_(fd);
            return "MHD_get_fdset() failed";
        }
        tv.tv_sec = 0;
        tv.tv_usec = 1000;
        MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv);
        MHD_run (d);
    }
    MHD_stop_daemon (d);
    MHD_socket_close_(fd);
    return NULL;
}
Exemplo n.º 4
0
/**
 * Run the MHD external event loop using select.
 *
 * @param daemon daemon to run it for
 */
static void
run_mhd_select_loop (struct MHD_Daemon *daemon)
{
  fd_set rs;
  fd_set ws;
  fd_set es;
  MHD_socket max_fd;
  MHD_UNSIGNED_LONG_LONG to;
  struct timeval tv;

  while (! done)
    {
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      max_fd = -1;
      to = 1000;

      if (MHD_YES !=
          MHD_get_fdset (daemon,
                         &rs,
                         &ws,
                         &es,
                         &max_fd))
        abort ();
      (void) MHD_get_timeout (daemon,
                              &to);
      if (1000 < to)
        to = 1000;
      tv.tv_sec = to / 1000;
      tv.tv_usec = 1000 * (to % 1000);
      if (0 > MHD_SYS_select_ (max_fd + 1,
                               &rs,
                               &ws,
                               &es,
                               &tv))
        abort ();
      MHD_run_from_select (daemon,
                           &rs,
                           &ws,
                           &es);
    }
}