GNU libmicrohttpd 1.0.9
Loading...
Searching...
No Matches
mhd_opt_matrix.c File Reference

The environment-driven daemon option matrix shared by the tests. More...

#include "platform.h"
#include <microhttpd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "mhd_opt_matrix.h"
Include dependency graph for mhd_opt_matrix.c:

Go to the source code of this file.

Macros

#define NUM_PROFILES    ((unsigned int) (sizeof(opt_profiles) / sizeof(opt_profiles[0])))
 

Functions

unsigned int mhd_opt_matrix_num_profiles (void)
 
const struct MHD_OptMatrixProfilemhd_opt_matrix_profile (unsigned int idx)
 
const struct MHD_OptMatrixProfilemhd_opt_matrix_lookup (const char *name_or_idx)
 
static int parse_threading (const char *s, enum MHD_OptMatrixThreading *out)
 
static int parse_poll (const char *s, enum MHD_OptMatrixPoll *out)
 
static _MHD_NORETURN void env_error (const char *name, const char *value)
 
const struct MHD_OptMatrixProfilemhd_opt_matrix_from_env (void)
 
int mhd_opt_matrix_effective_discipline (const struct MHD_OptMatrixProfile *prof)
 
int mhd_opt_matrix_profile_supported (const struct MHD_OptMatrixProfile *prof)
 
const char * mhd_opt_matrix_describe (const struct MHD_OptMatrixProfile *prof, char *buf, size_t buf_size)
 
unsigned int mhd_opt_matrix_fill_options (const struct MHD_OptMatrixProfile *prof, struct MHD_OptionItem *ops, unsigned int max_ops)
 
unsigned int mhd_opt_matrix_daemon_flags (const struct MHD_OptMatrixProfile *prof, unsigned int base_flags, int allow_external)
 
int mhd_opt_matrix_is_external (const struct MHD_OptMatrixProfile *prof)
 
int mhd_opt_matrix_raise_mem_limit (struct MHD_OptMatrixProfile *prof, size_t min_limit)
 
void mhd_opt_matrix_print_notice (const char *test_name)
 

Variables

static const struct MHD_OptMatrixProfile opt_profiles []
 
static int env_parsed
 
static int env_selected
 
static struct MHD_OptMatrixProfile env_profile
 
static char env_profile_name [64]
 

Detailed Description

The environment-driven daemon option matrix shared by the tests.

Author
Christian Grothoff

Definition in file mhd_opt_matrix.c.

Macro Definition Documentation

◆ NUM_PROFILES

#define NUM_PROFILES    ((unsigned int) (sizeof(opt_profiles) / sizeof(opt_profiles[0])))

The number of built-in profiles.

Definition at line 96 of file mhd_opt_matrix.c.

Referenced by mhd_opt_matrix_lookup(), mhd_opt_matrix_num_profiles(), and mhd_opt_matrix_profile().

Function Documentation

◆ env_error()

static _MHD_NORETURN void env_error ( const char * name,
const char * value )
static

Report a broken environment variable and terminate: a typo in a driver script must not silently produce a run with the default configuration.

Parameters
namethe name of the variable
valuethe offending value

Definition at line 215 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::name, and NULL.

Referenced by mhd_opt_matrix_from_env().

Here is the caller graph for this function:

◆ mhd_opt_matrix_daemon_flags()

unsigned int mhd_opt_matrix_daemon_flags ( const struct MHD_OptMatrixProfile * prof,
unsigned int base_flags,
int allow_external )

Combine the daemon flags required by prof with base_flags.

Parameters
profthe profile to apply, may be NULL (base_flags is returned)
base_flagsthe flags the caller wants in any case, e.g. MHD_USE_ERROR_LOG
allow_externalif zero, a profile that asks for external polling is served with an internal polling thread instead; use this in tests whose client cannot call MHD_run()
Returns
the flags for MHD_start_daemon()

Definition at line 458 of file mhd_opt_matrix.c.

References MHD_OPT_MATRIX_POLL_EPOLL, MHD_OPT_MATRIX_POLL_POLL, MHD_OPT_MATRIX_POLL_SELECT, MHD_OPT_MATRIX_THR_EXTERNAL, MHD_OPT_MATRIX_THR_INTERNAL, MHD_OPT_MATRIX_THR_PER_CONNECTION, MHD_OPT_MATRIX_THR_POOL, MHD_USE_EPOLL, MHD_USE_INTERNAL_POLLING_THREAD, MHD_USE_POLL, MHD_USE_THREAD_PER_CONNECTION, NULL, MHD_OptMatrixProfile::poll_backend, and MHD_OptMatrixProfile::threading.

◆ mhd_opt_matrix_describe()

const char * mhd_opt_matrix_describe ( const struct MHD_OptMatrixProfile * prof,
char * buf,
size_t buf_size )

Render a one-line, human readable description of prof.

Parameters
profthe profile to describe
[out]bufthe buffer to write to
buf_sizethe size of buf
Returns
buf

Definition at line 367 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::discipline_lvl, MHD_OptMatrixProfile::mem_limit, mhd_opt_matrix_effective_discipline(), MHD_OPT_MATRIX_THR_POOL, MHD_OptMatrixProfile::name, NULL, MHD_OptMatrixProfile::poll_backend, MHD_OptMatrixProfile::thread_pool_size, MHD_OptMatrixProfile::threading, and MHD_OptMatrixProfile::use_legacy_strict.

Referenced by mhd_opt_matrix_print_notice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mhd_opt_matrix_effective_discipline()

int mhd_opt_matrix_effective_discipline ( const struct MHD_OptMatrixProfile * prof)

Get the client discipline level that MHD will really use for prof.

This is not always prof->discipline_lvl: MHD_OPTION_STRICT_FOR_CLIENT only has two settings, and daemon.c:7102-7106 maps every value of -1 or below to level -3 (the most permissive one) and every value of 1 or above to level 1. A caller that decides what a request must do therefore has to ask for the effective level, not for the configured one - a test that believes it asked for "slightly lenient" in fact runs at -3.

Parameters
profthe profile to inspect, may be NULL (0 is returned then)
Returns
the client discipline level in effect

Definition at line 323 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::discipline_lvl, NULL, and MHD_OptMatrixProfile::use_legacy_strict.

Referenced by mhd_opt_matrix_describe().

Here is the caller graph for this function:

◆ mhd_opt_matrix_fill_options()

unsigned int mhd_opt_matrix_fill_options ( const struct MHD_OptMatrixProfile * prof,
struct MHD_OptionItem * ops,
unsigned int max_ops )

Fill ops with the options of prof.

The array is terminated with an MHD_OPTION_END element, so it can be passed to MHD_start_daemon() as

MHD_start_daemon (flags, port, NULL, NULL, ahc, cls,
                  MHD_OPTION_ARRAY, ops,
                  ... other options ...,
                  MHD_OPTION_END);

which works for a varargs call just as well as for a call that already uses MHD_OPTION_ARRAY.

Parameters
profthe profile to apply, may be NULL (only MHD_OPTION_END is stored then)
[out]opsthe array to fill
max_opsthe number of elements of ops, at least 4
Returns
the number of elements used, including the terminating MHD_OPTION_END; zero if ops is too small

Definition at line 414 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::discipline_lvl, MHD_OptMatrixProfile::mem_limit, MHD_OPT_MATRIX_THR_POOL, MHD_OPTION_CLIENT_DISCIPLINE_LVL, MHD_OPTION_CONNECTION_MEMORY_LIMIT, MHD_OPTION_END, MHD_OPTION_STRICT_FOR_CLIENT, MHD_OPTION_THREAD_POOL_SIZE, NULL, MHD_OptionItem::option, MHD_OptionItem::ptr_value, MHD_OptMatrixProfile::thread_pool_size, MHD_OptMatrixProfile::threading, MHD_OptMatrixProfile::use_legacy_strict, and MHD_OptionItem::value.

◆ mhd_opt_matrix_from_env()

const struct MHD_OptMatrixProfile * mhd_opt_matrix_from_env ( void )

Get the profile selected by the environment.

Returns
NULL if the environment selects nothing, in which case the caller must keep its own, previous configuration; otherwise a pointer to a static profile that stays valid until the next call

Definition at line 227 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::discipline_lvl, env_error(), env_parsed, env_profile, env_profile_name, env_selected, MHD_OptMatrixProfile::mem_limit, MHD_OPT_MATRIX_DISCP_ENV, mhd_opt_matrix_lookup(), MHD_OPT_MATRIX_MEM_ENV, MHD_OPT_MATRIX_POLL_ENV, MHD_OPT_MATRIX_PROFILE_ENV, MHD_OPT_MATRIX_STRICT_ENV, MHD_OPT_MATRIX_THR_POOL, MHD_OPT_MATRIX_THREADING_ENV, MHD_OptMatrixProfile::name, NULL, opt_profiles, parse_poll(), parse_threading(), MHD_OptMatrixProfile::poll_backend, MHD_OptMatrixProfile::thread_pool_size, MHD_OptMatrixProfile::threading, and MHD_OptMatrixProfile::use_legacy_strict.

Referenced by mhd_opt_matrix_print_notice().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mhd_opt_matrix_is_external()

int mhd_opt_matrix_is_external ( const struct MHD_OptMatrixProfile * prof)

Check whether prof needs the application to drive MHD_run().

Parameters
profthe profile to check, may be NULL
Returns
non-zero if the daemon has no internal thread

Definition at line 499 of file mhd_opt_matrix.c.

References MHD_OPT_MATRIX_THR_EXTERNAL, NULL, and MHD_OptMatrixProfile::threading.

◆ mhd_opt_matrix_lookup()

const struct MHD_OptMatrixProfile * mhd_opt_matrix_lookup ( const char * name_or_idx)

Look up a profile by name or by decimal index.

Parameters
name_or_idxthe name ("mem-512") or the index ("4")
Returns
the profile, or NULL if name_or_idx matches nothing

Definition at line 136 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::name, NULL, NUM_PROFILES, and opt_profiles.

Referenced by mhd_opt_matrix_from_env().

Here is the caller graph for this function:

◆ mhd_opt_matrix_num_profiles()

unsigned int mhd_opt_matrix_num_profiles ( void )

The number of built-in profiles.

Definition at line 122 of file mhd_opt_matrix.c.

References NUM_PROFILES.

◆ mhd_opt_matrix_print_notice()

void mhd_opt_matrix_print_notice ( const char * test_name)

Print the one-line notice naming the profile in use and, if a profile is selected, the profile.

Parameters
test_namethe name of the calling test, used as the line prefix

Definition at line 521 of file mhd_opt_matrix.c.

References mhd_opt_matrix_describe(), mhd_opt_matrix_from_env(), MHD_OptMatrixProfile::name, and NULL.

Here is the call graph for this function:

◆ mhd_opt_matrix_profile()

const struct MHD_OptMatrixProfile * mhd_opt_matrix_profile ( unsigned int idx)

Get the built-in profile number idx.

Profile zero is the "default" profile: the library defaults for every dimension plus one internal polling thread, i.e. the configuration the tests of this directory used before the matrix was introduced.

Parameters
idxthe index of the profile, wraps around
Returns
the profile, never NULL

Definition at line 129 of file mhd_opt_matrix.c.

References NUM_PROFILES, and opt_profiles.

◆ mhd_opt_matrix_profile_supported()

int mhd_opt_matrix_profile_supported ( const struct MHD_OptMatrixProfile * prof)

Check whether prof can be used by this build at run time.

Parameters
profthe profile to check
Returns
non-zero if the profile is usable, zero if the required threading support or polling backend is missing

Definition at line 339 of file mhd_opt_matrix.c.

References MHD_FEATURE_EPOLL, MHD_FEATURE_POLL, MHD_FEATURE_THREADS, MHD_is_feature_supported(), MHD_OPT_MATRIX_POLL_EPOLL, MHD_OPT_MATRIX_POLL_POLL, MHD_OPT_MATRIX_POLL_SELECT, MHD_OPT_MATRIX_THR_EXTERNAL, MHD_OPT_MATRIX_THR_PER_CONNECTION, MHD_YES, NULL, MHD_OptMatrixProfile::poll_backend, and MHD_OptMatrixProfile::threading.

Here is the call graph for this function:

◆ mhd_opt_matrix_raise_mem_limit()

int mhd_opt_matrix_raise_mem_limit ( struct MHD_OptMatrixProfile * prof,
size_t min_limit )

Raise the connection memory limit of prof to at least min_limit.

Tests that cannot work with a tiny connection pool (because the requests they must send do not fit into it) use this to keep the other dimensions of the matrix while staying functional. The change must be reported in the test output so that the log stays truthful.

Parameters
[in,out]profthe profile to adjust, must be a caller-owned copy
min_limitthe smallest acceptable limit, zero does nothing
Returns
non-zero if the limit was actually raised

Definition at line 508 of file mhd_opt_matrix.c.

References MHD_OptMatrixProfile::mem_limit, and NULL.

◆ parse_poll()

static int parse_poll ( const char * s,
enum MHD_OptMatrixPoll * out )
static

Parse the polling backend name.

Parameters
sthe name
[out]outthe parsed backend
Returns
non-zero on success

Definition at line 193 of file mhd_opt_matrix.c.

References MHD_OPT_MATRIX_POLL_EPOLL, MHD_OPT_MATRIX_POLL_POLL, and MHD_OPT_MATRIX_POLL_SELECT.

Referenced by mhd_opt_matrix_from_env().

Here is the caller graph for this function:

◆ parse_threading()

static int parse_threading ( const char * s,
enum MHD_OptMatrixThreading * out )
static

Parse the threading mode name.

Parameters
sthe name
[out]outthe parsed mode
Returns
non-zero on success

Definition at line 168 of file mhd_opt_matrix.c.

References MHD_OPT_MATRIX_THR_EXTERNAL, MHD_OPT_MATRIX_THR_INTERNAL, MHD_OPT_MATRIX_THR_PER_CONNECTION, and MHD_OPT_MATRIX_THR_POOL.

Referenced by mhd_opt_matrix_from_env().

Here is the caller graph for this function:

Variable Documentation

◆ env_parsed

int env_parsed
static

Non-zero once the environment has been read into env_profile.

Definition at line 103 of file mhd_opt_matrix.c.

Referenced by mhd_opt_matrix_from_env().

◆ env_profile

struct MHD_OptMatrixProfile env_profile
static

The profile derived from the environment.

Definition at line 113 of file mhd_opt_matrix.c.

Referenced by mhd_opt_matrix_from_env().

◆ env_profile_name

char env_profile_name[64]
static

The name of env_profile.

Definition at line 118 of file mhd_opt_matrix.c.

Referenced by mhd_opt_matrix_from_env().

◆ env_selected

int env_selected
static

Non-zero if the environment selects a profile at all.

Definition at line 108 of file mhd_opt_matrix.c.

Referenced by mhd_opt_matrix_from_env().

◆ opt_profiles

const struct MHD_OptMatrixProfile opt_profiles[]
static

The built-in matrix of daemon option profiles.

Every value of every dimension listed in the header appears at least once:

  • memory limit: 0 (default), 64, 128, 256, 512, 1024, 2048, 3072, 4096;
  • client discipline level: -3, -2, -1, 0, 1, 2, 3;
  • MHD_OPTION_STRICT_FOR_CLIENT with a positive and with a negative value;
  • threading: external polling, one internal thread, thread-per-connection, thread pool;
  • polling backend: select(), poll(), epoll.

Profile zero is "neutral": it is exactly the configuration the tests of this directory used before the matrix was introduced.

The combination "thread-per-connection + epoll" is deliberately absent: MHD rejects it (daemon.c:8680). External polling is always paired with the select()-style interface, as that is the only one the tests can drive.

Definition at line 54 of file mhd_opt_matrix.c.

Referenced by mhd_opt_matrix_from_env(), mhd_opt_matrix_lookup(), and mhd_opt_matrix_profile().