libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] 0.9.53 breaks MHD_USE_POLL?


From: Evgeny Grin
Subject: Re: [libmicrohttpd] 0.9.53 breaks MHD_USE_POLL?
Date: Wed, 26 Apr 2017 13:36:56 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Hi Lorenzo,

On 26.04.2017 11:56, Lorenzo Miniero wrote:
> 2017-04-25 18:36 GMT+02:00 Evgeny Grin <address@hidden
> <mailto:address@hidden>>:
>
>     Hi Lorenzo,
>
>     Thanks for report!
>     We introduced more checks in release 0.9.53 to make MHD more
>     foolproof.
>     Now MHD reject invalid combinations of flags instead of starting with
>     undefined behaviour.
>     Applications are advised to set explicitly flag
>     MHD_USE_INTERNAL_POLLING_THREAD when using
>     MHD_USE_THREAD_PER_CONNECTION.
>     Currently MHD_USE_THREAD_PER_CONNECTION flag also enforce implicit
>     setting of MHD_USE_INTERNAL_POLLING_THREAD.
>     I fixed check to improve backward compatibility with
>     MHD_USE_THREAD_PER_CONNECTION and MHD_USE_POLL without
>     MHD_USE_INTERNAL_POLLING_THREAD.
>
>     If application will be used with new version of MHD, I strongly advise
>     to use MHD_USE_AUTO instead of MHD_USE_POLL or MHD_USE_EPOLL
>     (unless you
>     have specific reason to use poll() or epoll). With MHD_USE_AUTO
>     you will
>     get best performance on any platform.
>
>     If you know any rejected valid combination of flags - let me know.
>     We'll
>     probably make a bugfix release soon.
>
>
> thanks for the quick response!
>
> MHD_USE_AUTO does indeed seem to be the easiest fix, here, although it
> looks like a recent addition (last November?) and so might not be
> available in deployments that still ship an older version of the
> library. Adding MHD_USE_INTERNAL_POLLING_THREAD where MHD_USE_POLL is
> specified might do the trick too, but that also was only recently
> added. It is available on both my Fedora and on some 16.04 Ubuntu
> boxes we have (which are on 0.9.33), but not sure if the same can be
> said for all the people using our code at the moment, so I'll have to
> fix the code so that it can "adapt".
The old (and confusing) name of MHD_USE_INTERNAL_POLLING_THREAD was
MHD_USE_SELECT_INTERNALLY. It *should *be used even with MHD_USE_POLL if
you want to run MHD internal threads.
So, pretty simple fix is to use MHD_USE_POLL | MHD_USE_SELECT_INTERNALLY
| MHD_USE_THREAD_PER_CONNECTION combination.
It is compilable with old MHD versions as well as with new versions.
You can simplify even more and use predefined combination:
MHD_USE_POLL_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION (new name is
MHD_USE_POLL_INTERNAL_THREAD | MHD_USE_THREAD_PER_CONNECTION).
>
> Using an #ifdef to see if those flags exist and react accordingly
> wouldn't work, as they're an enum and not defines. I guess that one
> way to do that without involving configure checks could be looking
> at MHD_VERSION: if it's higher than X, then we can use MHD_USE_AUTO,
> otherwise we do what worked for us so far. Not sure what X is, though:
> do you know the programmatic version number of when the feature was added?
>
You found answer already, as I see.

I could suggest you to use following macro to make code compilable with
older MHD version on all platforms:
#if MHD_VERSION < 0x00095208
#  define MHD_USE_AUTO 0
#endif /* MHD_VERSION < 0x00095208 */

daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_SELECT_INTERNALLY,
        port, NULL, NULL, &handler, &h_cls, MHD_OPTION_END);

In this case older MHD versions will use select() and never versions
will use best available polling functions (select(), poll(), epoll).

Alternatively, if your application is used only on platforms where
poll() is available:
#if MHD_VERSION < 0x00095208
#  define MHD_USE_AUTO MHD_USE_POLL
#endif /* MHD_VERSION < 0x00095208 */

daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_SELECT_INTERNALLY,
        port, NULL, NULL, &handler, &h_cls, MHD_OPTION_END);

In this case older MHD versions will use poll() and never versions will
use best available polling functions (select(), poll(), epoll).

-- 

Best Wishes,
Evgeny Grin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]