[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] minor issue with epoll+external select+no_timeout
From: |
Christian Grothoff |
Subject: |
Re: [libmicrohttpd] minor issue with epoll+external select+no_timeout |
Date: |
Wed, 18 Jun 2014 21:12:46 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.5.0 |
Hi!
Interesting workaround, but obviously this is not how it should be.
However, I am not sure I can see how this happens. In daemon.c:3537
MHD_start_daemon_va() makes a call to 'setup_epoll_to_listen()' and in
that function in line daemon.c:3253 the listen FD is added to the epoll set.
For the combination of flags you state, I do not quite see how the
respective paths would not be taken (without triggering a jump to
'free_and_fail' which means MHD_start_daemon() would return NULL).
So to further understand, analyze and hopefully improve the situation,
could you say which version of MHD are you using, and --- especially if
you are using a release >= 0.9.35 --- could you please try to use gdb to
see how MHD runs through the MHD_start_daemon()-routine without
triggering the epoll call in line 3253?
Happy hacking!
Christian
On 06/18/2014 11:40 AM, Marcos Pindado Sebastian wrote:
> Hi,
>
> I want to share this little issue I had while implementing an external select
> webserver.
> Case: daemon configured with MHD_USE_EPOLL_LINUX_ONLY plus EXTERNAL_SELECT.
>
> The typical example for the external select is:
>
> MHD_start_daemon (epoll)
> while (1)
> {
> MHD_get_fdset (...)
> MHD_get_timeout(...)
> select(fds, timeout)
> MHD_run
> }
>
> Well, the example worked as far as I noticed that timeout had value 0 (not
> null), meaning not waiting at all. When I changed it to NULL then the example
> stopped working, because the program got blocked in the select statement not
> being notified of incoming connections.
> The problem is, MHD_start_daemon, creates the epollFD before the
> listen-socket is set up. So, get_fdset returns a well epoll-fd without any
> listen socket attached just after start_daemon returns.
>
> The solution for this is very simple, call MHD_run one time after the daemon
> is started and before the select-loop:
>
> MHD_start_daemon (epoll)
> MHD_run // => The listen socket is attached to the epollFD
> while (1)
> {select/run}
>
>
> Thanks for your work!
> ____________
> Verificada la ausencia de virus por G Data MailSecurity
>
> VersiĆ³n: AVA 24.2721 del 18.06.2014
> Noticias de virus: www.antiviruslab.com
>