2017-04-26 12:36 GMT+02:00 Evgeny Grin <[email protected]>:

> Hi Lorenzo,
>
> On 26.04.2017 11:56, Lorenzo Miniero wrote:
> > 2017-04-25 18:36 GMT+02:00 Evgeny Grin <[email protected]
> > <mailto:[email protected]>>:
> >
> >     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).
>
>

Thanks! So, just to clarify, when doing MHD_USE_THREAD_PER_CONNECTION, even
with MHD_USE_AUTO you still need to specify  MHD_USE_SELECT_INTERNALLY (or
the newer MHD_USE_INTERNAL_POLLING_THREAD), or does MHD_USE_AUTO also
automatically sets the correct threading model? Asking because the way I
was addressing this in a pull request on my project was simply to do a:

#if MHD_VERSION >= 0x00095208
MHD_USE_THREAD_PER_CONNECTION | MHD_USE_AUTO | MHD_USE_DUAL_STACK,
#else
MHD_USE_THREAD_PER_CONNECTION | MHD_USE_POLL | MHD_USE_DUAL_STACK,
#endif

which seems to be working as expected on 0.9.53.

Thanks!
Lorenzo


--
>
> Best Wishes,
> Evgeny Grin
>
>
>

Reply via email to