On 12/2/19 9:55 PM, José Bollo wrote:
> 
> I tried to write something like "while(true) MHD_run();" but strace
> showed its inefficiency.

Oh my. Yes, that'd be bad.

> IMHO it can make sense: "1. setup 2. run" without exit conditon and not
> bound to any stdin, i.e. a normal unix daemon.
> 

Well, that's trivial. Please consider the attached fragment (not tested,
but should be very close to what you need, modulo error handling).
// launch MHD with MHD_USE_EPOLL (and NOT any "INTERNAL_THREAD")
{
  int fd;

  fd = MHD_get_daemon_info (daemon,
                            MHD_DAEMON_INFO_EPOLL_FD)->epoll_fd;
  while (1)
  {
    fd_set r;
    MHD_UNSIGNED_LONG_LONG to;
    struct timeval tv;

    FD_ZERO (&r);
    FD_SET (fd, &r);
    MHD_get_timeout (daemon, &to);
    tv.tv_sec = (to / 1000LLU);
    tv.tv_usec = (to % 1000LLU) * 1000;
    select (r + 1, &r, NULL, NULL, NULL);
    MHD_run (daemon);
  }
}

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to