Apache HTTPD
Classes | Macros | Functions | Variables
h2_mplx.c File Reference
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <apr_atomic.h>
#include <apr_thread_mutex.h>
#include <apr_thread_cond.h>
#include <apr_strings.h>
#include <apr_time.h>
#include <httpd.h>
#include <http_core.h>
#include <http_connection.h>
#include <http_log.h>
#include <http_protocol.h>
#include <mpm_common.h>
#include "mod_http2.h"
#include "h2.h"
#include "h2_private.h"
#include "h2_bucket_beam.h"
#include "h2_config.h"
#include "h2_c1.h"
#include "h2_conn_ctx.h"
#include "h2_protocol.h"
#include "h2_mplx.h"
#include "h2_request.h"
#include "h2_stream.h"
#include "h2_session.h"
#include "h2_c2.h"
#include "h2_workers.h"
#include "h2_util.h"

Go to the source code of this file.

Classes

struct  stream_iter_ctx
 
struct  stream_iter_ctx_t
 
struct  stream_iter_aws_t
 

Macros

#define H2_MPLX_ENTER(m)
 
#define H2_MPLX_LEAVE(m)    apr_thread_mutex_unlock(m->lock)
 
#define H2_MPLX_ENTER_ALWAYS(m)    apr_thread_mutex_lock(m->lock)
 
#define H2_MPLX_ENTER_MAYBE(m, dolock)    if (dolock) apr_thread_mutex_lock(m->lock)
 
#define H2_MPLX_LEAVE_MAYBE(m, dolock)    if (dolock) apr_thread_mutex_unlock(m->lock)
 

Functions

static conn_recc2_prod_next (void *baton, int *phas_more)
 
static void c2_prod_done (void *baton, conn_rec *c2)
 
static void workers_shutdown (void *baton, int graceful)
 
static void s_mplx_be_happy (h2_mplx *m, conn_rec *c, h2_conn_ctx_t *conn_ctx)
 
static void m_be_annoyed (h2_mplx *m)
 
static apr_status_t mplx_pollset_create (h2_mplx *m)
 
static apr_status_t mplx_pollset_poll (h2_mplx *m, apr_interval_time_t timeout, stream_ev_callback *on_stream_input, stream_ev_callback *on_stream_output, void *on_ctx)
 
static int abort_on_oom (int retcode)
 
apr_status_t h2_mplx_c1_child_init (apr_pool_t *pool, server_rec *s)
 
static void c1_input_consumed (void *ctx, h2_bucket_beam *beam, apr_off_t length)
 
static int stream_is_running (h2_stream *stream)
 
int h2_mplx_c1_stream_is_running (h2_mplx *m, h2_stream *stream)
 
static void c1c2_stream_joined (h2_mplx *m, h2_stream *stream)
 
static void m_stream_cleanup (h2_mplx *m, h2_stream *stream)
 
static h2_c2_transitc2_transit_create (h2_mplx *m)
 
static void c2_transit_destroy (h2_c2_transit *transit)
 
static h2_c2_transitc2_transit_get (h2_mplx *m)
 
static void c2_transit_recycle (h2_mplx *m, h2_c2_transit *transit)
 
h2_mplxh2_mplx_c1_create (int child_num, apr_uint32_t id, h2_stream *stream0, server_rec *s, apr_pool_t *parent, h2_workers *workers)
 
int h2_mplx_c1_shutdown (h2_mplx *m)
 
static int m_stream_iter_wrap (void *ctx, void *stream)
 
apr_status_t h2_mplx_c1_streams_do (h2_mplx *m, h2_mplx_stream_cb *cb, void *ctx)
 
static int m_stream_want_send_data (void *ctx, void *stream)
 
int h2_mplx_c1_all_streams_want_send_data (h2_mplx *m)
 
static int m_report_stream_iter (void *ctx, void *val)
 
static int m_unexpected_stream_iter (void *ctx, void *val)
 
static int m_stream_cancel_iter (void *ctx, void *val)
 
static void c1_purge_streams (h2_mplx *m)
 
void h2_mplx_c1_destroy (h2_mplx *m)
 
apr_status_t h2_mplx_c1_stream_cleanup (h2_mplx *m, h2_stream *stream, unsigned int *pstream_count)
 
const h2_streamh2_mplx_c2_stream_get (h2_mplx *m, int stream_id)
 
void h2_mplx_c1_going_keepalive (h2_mplx *m)
 
apr_status_t h2_mplx_c1_poll (h2_mplx *m, apr_interval_time_t timeout, stream_ev_callback *on_stream_input, stream_ev_callback *on_stream_output, void *on_ctx)
 
apr_status_t h2_mplx_c1_reprioritize (h2_mplx *m, h2_stream_pri_cmp_fn *cmp, h2_session *session)
 
static apr_status_t c1_process_stream (h2_mplx *m, h2_stream *stream, h2_stream_pri_cmp_fn *cmp, h2_session *session)
 
void h2_mplx_c1_process (h2_mplx *m, h2_iqueue *ready_to_process, h2_stream_get_fn *get_stream, h2_stream_pri_cmp_fn *stream_pri_cmp, h2_session *session, unsigned int *pstream_count)
 
static void c2_beam_input_write_notify (void *ctx, h2_bucket_beam *beam)
 
static void add_stream_poll_event (h2_mplx *m, int stream_id, h2_iqueue *q)
 
static void c2_beam_input_read_notify (void *ctx, h2_bucket_beam *beam)
 
static void c2_beam_input_read_eagain (void *ctx, h2_bucket_beam *beam)
 
static void c2_beam_output_write_notify (void *ctx, h2_bucket_beam *beam)
 
static apr_status_t c2_setup_io (h2_mplx *m, conn_rec *c2, h2_stream *stream, h2_c2_transit *transit)
 
static conn_recs_next_c2 (h2_mplx *m)
 
static void s_c2_done (h2_mplx *m, conn_rec *c2, h2_conn_ctx_t *conn_ctx)
 
static int reset_is_acceptable (h2_stream *stream)
 
apr_status_t h2_mplx_c1_client_rst (h2_mplx *m, int stream_id, h2_stream *stream)
 

Variables

static apr_pool_tpchild
 

Macro Definition Documentation

◆ H2_MPLX_ENTER

#define H2_MPLX_ENTER (   m)
Value:
return rv_lock;\
} } while(0)
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const void * m

Definition at line 89 of file h2_mplx.c.

◆ H2_MPLX_ENTER_ALWAYS

#define H2_MPLX_ENTER_ALWAYS (   m)     apr_thread_mutex_lock(m->lock)

Definition at line 97 of file h2_mplx.c.

◆ H2_MPLX_ENTER_MAYBE

#define H2_MPLX_ENTER_MAYBE (   m,
  dolock 
)     if (dolock) apr_thread_mutex_lock(m->lock)

Definition at line 100 of file h2_mplx.c.

◆ H2_MPLX_LEAVE

#define H2_MPLX_LEAVE (   m)     apr_thread_mutex_unlock(m->lock)

Definition at line 94 of file h2_mplx.c.

◆ H2_MPLX_LEAVE_MAYBE

#define H2_MPLX_LEAVE_MAYBE (   m,
  dolock 
)     if (dolock) apr_thread_mutex_unlock(m->lock)

Definition at line 103 of file h2_mplx.c.

Function Documentation

◆ abort_on_oom()

static int abort_on_oom ( int  retcode)
static

Definition at line 77 of file h2_mplx.c.

◆ add_stream_poll_event()

static void add_stream_poll_event ( h2_mplx m,
int  stream_id,
h2_iqueue q 
)
static

Definition at line 777 of file h2_mplx.c.

◆ c1_input_consumed()

static void c1_input_consumed ( void *  ctx,
h2_bucket_beam beam,
apr_off_t  length 
)
static

Definition at line 106 of file h2_mplx.c.

◆ c1_process_stream()

static apr_status_t c1_process_stream ( h2_mplx m,
h2_stream stream,
h2_stream_pri_cmp_fn cmp,
h2_session session 
)
static

Definition at line 664 of file h2_mplx.c.

◆ c1_purge_streams()

static void c1_purge_streams ( h2_mplx m)
static

Definition at line 574 of file h2_mplx.c.

◆ c1c2_stream_joined()

static void c1c2_stream_joined ( h2_mplx m,
h2_stream stream 
)
static

Definition at line 128 of file h2_mplx.c.

◆ c2_beam_input_read_eagain()

static void c2_beam_input_read_eagain ( void *  ctx,
h2_bucket_beam beam 
)
static

Definition at line 798 of file h2_mplx.c.

◆ c2_beam_input_read_notify()

static void c2_beam_input_read_notify ( void *  ctx,
h2_bucket_beam beam 
)
static

Definition at line 787 of file h2_mplx.c.

◆ c2_beam_input_write_notify()

static void c2_beam_input_write_notify ( void *  ctx,
h2_bucket_beam beam 
)
static

Definition at line 766 of file h2_mplx.c.

◆ c2_beam_output_write_notify()

static void c2_beam_output_write_notify ( void *  ctx,
h2_bucket_beam beam 
)
static

Definition at line 811 of file h2_mplx.c.

◆ c2_prod_done()

static void c2_prod_done ( void *  baton,
conn_rec c2 
)
static

Definition at line 1011 of file h2_mplx.c.

◆ c2_prod_next()

static conn_rec * c2_prod_next ( void *  baton,
int phas_more 
)
static

Definition at line 924 of file h2_mplx.c.

◆ c2_setup_io()

static apr_status_t c2_setup_io ( h2_mplx m,
conn_rec c2,
h2_stream stream,
h2_c2_transit transit 
)
static

Definition at line 822 of file h2_mplx.c.

◆ c2_transit_create()

static h2_c2_transit * c2_transit_create ( h2_mplx m)
static

Definition at line 186 of file h2_mplx.c.

◆ c2_transit_destroy()

static void c2_transit_destroy ( h2_c2_transit transit)
static

Definition at line 222 of file h2_mplx.c.

◆ c2_transit_get()

static h2_c2_transit * c2_transit_get ( h2_mplx m)
static

Definition at line 227 of file h2_mplx.c.

◆ c2_transit_recycle()

static void c2_transit_recycle ( h2_mplx m,
h2_c2_transit transit 
)
static

Definition at line 236 of file h2_mplx.c.

◆ h2_mplx_c1_all_streams_want_send_data()

int h2_mplx_c1_all_streams_want_send_data ( h2_mplx m)

Return != 0 iff all open streams want to send data

Definition at line 411 of file h2_mplx.c.

◆ h2_mplx_c1_child_init()

apr_status_t h2_mplx_c1_child_init ( apr_pool_t pool,
server_rec s 
)

Definition at line 83 of file h2_mplx.c.

◆ h2_mplx_c1_client_rst()

apr_status_t h2_mplx_c1_client_rst ( h2_mplx m,
int  stream_id,
struct h2_stream stream 
)

A stream has been RST_STREAM by the client. Abort any processing going on and remove from processing queue.

Definition at line 1122 of file h2_mplx.c.

◆ h2_mplx_c1_create()

h2_mplx * h2_mplx_c1_create ( int  child_num,
apr_uint32_t  id,
h2_stream stream0,
server_rec s,
apr_pool_t parent,
h2_workers workers 
)

A h2_mplx needs to be thread-safe and if will be called by the h2_session thread and the h2_worker threads. Therefore:

  • calls are protected by a mutex lock, m->lock
  • the pool needs its own allocator, since apr_allocator_t are not re-entrant. The separate allocator works without a separate lock since we already protect h2_mplx itself. Since HTTP/2 connections can be expected to live longer than their HTTP/1 cousins, the separate allocator seems to work better than protecting a shared h2_session one with an own lock.

Definition at line 258 of file h2_mplx.c.

◆ h2_mplx_c1_destroy()

void h2_mplx_c1_destroy ( h2_mplx m)

Destroy the mplx, shutting down all ongoing processing.

Parameters
mthe mplx destroyed
waitcondition var to wait on for ref counter == 0

Definition at line 471 of file h2_mplx.c.

◆ h2_mplx_c1_going_keepalive()

void h2_mplx_c1_going_keepalive ( h2_mplx m)

Session processing is entering KEEPALIVE, e.g. giving control to the MPM for monitoring incoming socket events only. Last chance for maintenance work before losing control.

Definition at line 605 of file h2_mplx.c.

◆ h2_mplx_c1_poll()

apr_status_t h2_mplx_c1_poll ( h2_mplx m,
apr_interval_time_t  timeout,
stream_ev_callback on_stream_input,
stream_ev_callback on_stream_output,
void *  on_ctx 
)

Poll the primary connection for input and the active streams for output. Invoke the callback for any stream where an event happened.

Definition at line 614 of file h2_mplx.c.

◆ h2_mplx_c1_process()

void h2_mplx_c1_process ( h2_mplx m,
struct h2_iqueue read_to_process,
h2_stream_get_fn get_stream,
h2_stream_pri_cmp_fn cmp,
struct h2_session session,
unsigned int pstream_count 
)

Process a stream request.

Parameters
mthe multiplexer
read_to_process
input_pending
cmpthe stream priority compare function
pstream_counton return the number of streams active in mplx

Definition at line 711 of file h2_mplx.c.

◆ h2_mplx_c1_reprioritize()

apr_status_t h2_mplx_c1_reprioritize ( h2_mplx m,
h2_stream_pri_cmp_fn cmp,
struct h2_session session 
)

Stream priorities have changed, reschedule pending requests.

Parameters
mthe multiplexer
cmpthe stream priority compare function
ctxcontext data for the compare function

Definition at line 643 of file h2_mplx.c.

◆ h2_mplx_c1_shutdown()

int h2_mplx_c1_shutdown ( h2_mplx m)

Shut down the multiplexer gracefully. Will no longer schedule new streams but let the ongoing ones finish normally.

Returns
the highest stream id being/been processed

Definition at line 358 of file h2_mplx.c.

◆ h2_mplx_c1_stream_cleanup()

apr_status_t h2_mplx_c1_stream_cleanup ( h2_mplx m,
struct h2_stream stream,
unsigned int pstream_count 
)

Notifies mplx that a stream has been completely handled on the main connection and is ready for cleanup.

Parameters
mthe mplx itself
streamthe stream ready for cleanup
pstream_countreturn the number of streams active

Definition at line 549 of file h2_mplx.c.

◆ h2_mplx_c1_stream_is_running()

int h2_mplx_c1_stream_is_running ( h2_mplx m,
h2_stream stream 
)

Definition at line 118 of file h2_mplx.c.

◆ h2_mplx_c1_streams_do()

apr_status_t h2_mplx_c1_streams_do ( h2_mplx m,
h2_mplx_stream_cb cb,
void *  ctx 
)

Iterate over all streams known to mplx from the primary connection.

Parameters
mthe mplx
cbthe callback to invoke on each stream
ctxuserdata passed to the callback

Definition at line 383 of file h2_mplx.c.

◆ h2_mplx_c2_stream_get()

const h2_stream * h2_mplx_c2_stream_get ( h2_mplx m,
int  stream_id 
)

Get readonly access to a stream for a secondary connection.

Definition at line 562 of file h2_mplx.c.

◆ m_be_annoyed()

static void m_be_annoyed ( h2_mplx m)
static

Definition at line 1066 of file h2_mplx.c.

◆ m_report_stream_iter()

static int m_report_stream_iter ( void *  ctx,
void *  val 
)
static

Definition at line 422 of file h2_mplx.c.

◆ m_stream_cancel_iter()

static int m_stream_cancel_iter ( void *  ctx,
void *  val 
)
static

Definition at line 455 of file h2_mplx.c.

◆ m_stream_cleanup()

static void m_stream_cleanup ( h2_mplx m,
h2_stream stream 
)
static

Definition at line 136 of file h2_mplx.c.

◆ m_stream_iter_wrap()

static int m_stream_iter_wrap ( void *  ctx,
void *  stream 
)
static

Definition at line 377 of file h2_mplx.c.

◆ m_stream_want_send_data()

static int m_stream_want_send_data ( void *  ctx,
void *  stream 
)
static

Definition at line 402 of file h2_mplx.c.

◆ m_unexpected_stream_iter()

static int m_unexpected_stream_iter ( void *  ctx,
void *  val 
)
static

Definition at line 446 of file h2_mplx.c.

◆ mplx_pollset_create()

static apr_status_t mplx_pollset_create ( h2_mplx m)
static

< Poll operations are interruptable by * apr_pollset_wakeup() or apr_pollcb_wakeup()

Definition at line 1154 of file h2_mplx.c.

◆ mplx_pollset_poll()

static apr_status_t mplx_pollset_poll ( h2_mplx m,
apr_interval_time_t  timeout,
stream_ev_callback on_stream_input,
stream_ev_callback on_stream_output,
void *  on_ctx 
)
static

Definition at line 1161 of file h2_mplx.c.

◆ reset_is_acceptable()

static int reset_is_acceptable ( h2_stream stream)
static

Definition at line 1100 of file h2_mplx.c.

◆ s_c2_done()

static void s_c2_done ( h2_mplx m,
conn_rec c2,
h2_conn_ctx_t conn_ctx 
)
static

Definition at line 938 of file h2_mplx.c.

◆ s_mplx_be_happy()

static void s_mplx_be_happy ( h2_mplx m,
conn_rec c,
h2_conn_ctx_t conn_ctx 
)
static

Definition at line 1046 of file h2_mplx.c.

◆ s_next_c2()

static conn_rec * s_next_c2 ( h2_mplx m)
static

Definition at line 870 of file h2_mplx.c.

◆ stream_is_running()

static int stream_is_running ( h2_stream stream)
static

Definition at line 111 of file h2_mplx.c.

◆ workers_shutdown()

static void workers_shutdown ( void *  baton,
int  graceful 
)
static

Definition at line 1026 of file h2_mplx.c.

Variable Documentation

◆ pchild

apr_pool_t* pchild
static

Definition at line 74 of file h2_mplx.c.