On Mon, 2 Dec 2019 22:03:51 +0100 Christian Grothoff <groth...@gnunet.org> wrote:
> 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). I know it is trivial (my implementation below) but I advocate to offer a facility that does the job. It avoids tricky aspects like EPOLL and get_daemon_info (is working for windows???) mhd = MHD_start_daemon(MHD_USE_EPOLL, ... if (!mhd) return 1; info = MHD_get_daemon_info(mhd, MHD_DAEMON_INFO_EPOLL_FD); if (info == NULL) { MHD_stop_daemon(mhd); return 2; } pfd.fd = info->epoll_fd; pfd.events = POLLIN; for(;;) { if (MHD_get_timeout(mhd, &to) == MHD_NO) i = -1; else i = (int)to; poll(&pfd, 1, i); MHD_run(mhd); } MHD_stop_daemon (mhd); return 0;