|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef __mod_h2__h2_mplx__
|
|
Packit |
90a5c9 |
#define __mod_h2__h2_mplx__
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* The stream multiplexer. It pushes buckets from the connection
|
|
Packit |
90a5c9 |
* thread to the stream threads and vice versa. It's thread-safe
|
|
Packit |
90a5c9 |
* to use.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* There is one h2_mplx instance for each h2_session, which sits on top
|
|
Packit |
90a5c9 |
* of a particular httpd conn_rec. Input goes from the connection to
|
|
Packit |
90a5c9 |
* the stream tasks. Output goes from the stream tasks to the connection,
|
|
Packit |
90a5c9 |
* e.g. the client.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* For each stream, there can be at most "H2StreamMaxMemSize" output bytes
|
|
Packit |
90a5c9 |
* queued in the multiplexer. If a task thread tries to write more
|
|
Packit |
90a5c9 |
* data, it is blocked until space becomes available.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Writing input is never blocked. In order to use flow control on the input,
|
|
Packit |
90a5c9 |
* the mplx can be polled for input data consumption.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct apr_pool_t;
|
|
Packit |
90a5c9 |
struct apr_thread_mutex_t;
|
|
Packit |
90a5c9 |
struct apr_thread_cond_t;
|
|
Packit |
90a5c9 |
struct h2_bucket_beam;
|
|
Packit |
90a5c9 |
struct h2_config;
|
|
Packit |
90a5c9 |
struct h2_ihash_t;
|
|
Packit |
90a5c9 |
struct h2_task;
|
|
Packit |
90a5c9 |
struct h2_stream;
|
|
Packit |
90a5c9 |
struct h2_request;
|
|
Packit |
90a5c9 |
struct apr_thread_cond_t;
|
|
Packit |
90a5c9 |
struct h2_workers;
|
|
Packit |
90a5c9 |
struct h2_iqueue;
|
|
Packit |
90a5c9 |
struct h2_ngn_shed;
|
|
Packit |
90a5c9 |
struct h2_req_engine;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <apr_queue.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct h2_mplx h2_mplx;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_mplx {
|
|
Packit |
90a5c9 |
long id;
|
|
Packit |
90a5c9 |
conn_rec *c;
|
|
Packit |
90a5c9 |
apr_pool_t *pool;
|
|
Packit |
90a5c9 |
server_rec *s; /* server for master conn */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
unsigned int event_pending;
|
|
Packit |
90a5c9 |
unsigned int aborted;
|
|
Packit |
90a5c9 |
unsigned int is_registered; /* is registered at h2_workers */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_ihash_t *streams; /* all streams currently processing */
|
|
Packit |
90a5c9 |
struct h2_ihash_t *sredo; /* all streams that need to be re-started */
|
|
Packit |
90a5c9 |
struct h2_ihash_t *shold; /* all streams done with task ongoing */
|
|
Packit |
90a5c9 |
struct h2_ihash_t *spurge; /* all streams done, ready for destroy */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_iqueue *q; /* all stream ids that need to be started */
|
|
Packit |
90a5c9 |
struct h2_ififo *readyq; /* all stream ids ready for output */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_ihash_t *redo_tasks; /* all tasks that need to be redone */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int max_streams; /* max # of concurrent streams */
|
|
Packit |
90a5c9 |
int max_stream_started; /* highest stream id that started processing */
|
|
Packit |
90a5c9 |
int tasks_active; /* # of tasks being processed from this mplx */
|
|
Packit |
90a5c9 |
int limit_active; /* current limit on active tasks, dynamic */
|
|
Packit |
90a5c9 |
int max_active; /* max, hard limit # of active tasks in a process */
|
|
Packit |
90a5c9 |
apr_time_t last_idle_block; /* last time, this mplx entered IDLE while
|
|
Packit |
90a5c9 |
* streams were ready */
|
|
Packit |
90a5c9 |
apr_time_t last_limit_change; /* last time, worker limit changed */
|
|
Packit |
90a5c9 |
apr_interval_time_t limit_change_interval;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_thread_mutex_t *lock;
|
|
Packit |
90a5c9 |
struct apr_thread_cond_t *added_output;
|
|
Packit |
90a5c9 |
struct apr_thread_cond_t *task_thawed;
|
|
Packit |
90a5c9 |
struct apr_thread_cond_t *join_wait;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_size_t stream_max_mem;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_t *spare_io_pool;
|
|
Packit |
90a5c9 |
apr_array_header_t *spare_slaves; /* spare slave connections */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_workers *workers;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_ngn_shed *ngn_shed;
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* Object lifecycle and information.
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_child_init(apr_pool_t *pool, server_rec *s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Create the multiplexer for the given HTTP2 session.
|
|
Packit |
90a5c9 |
* Implicitly has reference count 1.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
h2_mplx *h2_mplx_create(conn_rec *c, apr_pool_t *master,
|
|
Packit |
90a5c9 |
const struct h2_config *conf,
|
|
Packit |
90a5c9 |
struct h2_workers *workers);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Decreases the reference counter of this mplx and waits for it
|
|
Packit |
90a5c9 |
* to reached 0, destroy the mplx afterwards.
|
|
Packit |
90a5c9 |
* This is to be called from the thread that created the mplx in
|
|
Packit |
90a5c9 |
* the first place.
|
|
Packit |
90a5c9 |
* @param m the mplx to be released and destroyed
|
|
Packit |
90a5c9 |
* @param wait condition var to wait on for ref counter == 0
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
void h2_mplx_release_and_join(h2_mplx *m, struct apr_thread_cond_t *wait);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_pop_task(h2_mplx *m, struct h2_task **ptask);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void h2_mplx_task_done(h2_mplx *m, struct h2_task *task, struct h2_task **ptask);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Shut down the multiplexer gracefully. Will no longer schedule new streams
|
|
Packit |
90a5c9 |
* but let the ongoing ones finish normally.
|
|
Packit |
90a5c9 |
* @return the highest stream id being/been processed
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
int h2_mplx_shutdown(h2_mplx *m);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int h2_mplx_is_busy(h2_mplx *m);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* IO lifetime of streams.
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_stream *h2_mplx_stream_get(h2_mplx *m, int id);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Notifies mplx that a stream has been completely handled on the main
|
|
Packit |
90a5c9 |
* connection and is ready for cleanup.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param m the mplx itself
|
|
Packit |
90a5c9 |
* @param stream the stream ready for cleanup
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_stream_cleanup(h2_mplx *m, struct h2_stream *stream);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Waits on output data from any stream in this session to become available.
|
|
Packit |
90a5c9 |
* Returns APR_TIMEUP if no data arrived in the given time.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_out_trywait(h2_mplx *m, apr_interval_time_t timeout,
|
|
Packit |
90a5c9 |
struct apr_thread_cond_t *iowait);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_keep_active(h2_mplx *m, struct h2_stream *stream);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* Stream processing.
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Process a stream request.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param m the multiplexer
|
|
Packit |
90a5c9 |
* @param stream the identifier of the stream
|
|
Packit |
90a5c9 |
* @param r the request to be processed
|
|
Packit |
90a5c9 |
* @param cmp the stream priority compare function
|
|
Packit |
90a5c9 |
* @param ctx context data for the compare function
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_process(h2_mplx *m, struct h2_stream *stream,
|
|
Packit |
90a5c9 |
h2_stream_pri_cmp *cmp, void *ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Stream priorities have changed, reschedule pending requests.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param m the multiplexer
|
|
Packit |
90a5c9 |
* @param cmp the stream priority compare function
|
|
Packit |
90a5c9 |
* @param ctx context data for the compare function
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_reprioritize(h2_mplx *m, h2_stream_pri_cmp *cmp, void *ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef apr_status_t stream_ev_callback(void *ctx, struct h2_stream *stream);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Check if the multiplexer has events for the master connection pending.
|
|
Packit |
90a5c9 |
* @return != 0 iff there are events pending
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
int h2_mplx_has_master_events(h2_mplx *m);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Dispatch events for the master connection, such as
|
|
Packit |
90a5c9 |
± @param m the multiplexer
|
|
Packit |
90a5c9 |
* @param on_resume new output data has arrived for a suspended stream
|
|
Packit |
90a5c9 |
* @param ctx user supplied argument to invocation.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_dispatch_master_events(h2_mplx *m,
|
|
Packit |
90a5c9 |
stream_ev_callback *on_resume,
|
|
Packit |
90a5c9 |
void *ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int h2_mplx_awaits_data(h2_mplx *m);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef int h2_mplx_stream_cb(struct h2_stream *s, void *ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_stream_do(h2_mplx *m, h2_mplx_stream_cb *cb, void *ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* Output handling of streams.
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Opens the output for the given stream with the specified response.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_out_open(h2_mplx *mplx, int stream_id,
|
|
Packit |
90a5c9 |
struct h2_bucket_beam *beam);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* h2_mplx list Manipulation.
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* The magic pointer value that indicates the head of a h2_mplx list
|
|
Packit |
90a5c9 |
* @param b The mplx list
|
|
Packit |
90a5c9 |
* @return The magic pointer value
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_LIST_SENTINEL(b) APR_RING_SENTINEL((b), h2_mplx, link)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Determine if the mplx list is empty
|
|
Packit |
90a5c9 |
* @param b The list to check
|
|
Packit |
90a5c9 |
* @return true or false
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_LIST_EMPTY(b) APR_RING_EMPTY((b), h2_mplx, link)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Return the first mplx in a list
|
|
Packit |
90a5c9 |
* @param b The list to query
|
|
Packit |
90a5c9 |
* @return The first mplx in the list
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_LIST_FIRST(b) APR_RING_FIRST(b)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Return the last mplx in a list
|
|
Packit |
90a5c9 |
* @param b The list to query
|
|
Packit |
90a5c9 |
* @return The last mplx int he list
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_LIST_LAST(b) APR_RING_LAST(b)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Insert a single mplx at the front of a list
|
|
Packit |
90a5c9 |
* @param b The list to add to
|
|
Packit |
90a5c9 |
* @param e The mplx to insert
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_LIST_INSERT_HEAD(b, e) do { \
|
|
Packit |
90a5c9 |
h2_mplx *ap__b = (e); \
|
|
Packit |
90a5c9 |
APR_RING_INSERT_HEAD((b), ap__b, h2_mplx, link); \
|
|
Packit |
90a5c9 |
} while (0)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Insert a single mplx at the end of a list
|
|
Packit |
90a5c9 |
* @param b The list to add to
|
|
Packit |
90a5c9 |
* @param e The mplx to insert
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_LIST_INSERT_TAIL(b, e) do { \
|
|
Packit |
90a5c9 |
h2_mplx *ap__b = (e); \
|
|
Packit |
90a5c9 |
APR_RING_INSERT_TAIL((b), ap__b, h2_mplx, link); \
|
|
Packit |
90a5c9 |
} while (0)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Get the next mplx in the list
|
|
Packit |
90a5c9 |
* @param e The current mplx
|
|
Packit |
90a5c9 |
* @return The next mplx
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_NEXT(e) APR_RING_NEXT((e), link)
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Get the previous mplx in the list
|
|
Packit |
90a5c9 |
* @param e The current mplx
|
|
Packit |
90a5c9 |
* @return The previous mplx
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_PREV(e) APR_RING_PREV((e), link)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Remove a mplx from its list
|
|
Packit |
90a5c9 |
* @param e The mplx to remove
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define H2_MPLX_REMOVE(e) APR_RING_REMOVE((e), link)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* h2_mplx DoS protection
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Master connection has entered idle mode.
|
|
Packit |
90a5c9 |
* @param m the mplx instance of the master connection
|
|
Packit |
90a5c9 |
* @return != SUCCESS iff connection should be terminated
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_idle(h2_mplx *m);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*******************************************************************************
|
|
Packit |
90a5c9 |
* h2_req_engine handling
|
|
Packit |
90a5c9 |
******************************************************************************/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef void h2_output_consumed(void *ctx, conn_rec *c, apr_off_t consumed);
|
|
Packit |
90a5c9 |
typedef apr_status_t h2_mplx_req_engine_init(struct h2_req_engine *engine,
|
|
Packit |
90a5c9 |
const char *id,
|
|
Packit |
90a5c9 |
const char *type,
|
|
Packit |
90a5c9 |
apr_pool_t *pool,
|
|
Packit |
90a5c9 |
apr_size_t req_buffer_size,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
h2_output_consumed **pconsumed,
|
|
Packit |
90a5c9 |
void **pbaton);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_req_engine_push(const char *ngn_type,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
h2_mplx_req_engine_init *einit);
|
|
Packit |
90a5c9 |
apr_status_t h2_mplx_req_engine_pull(struct h2_req_engine *ngn,
|
|
Packit |
90a5c9 |
apr_read_type_e block,
|
|
Packit |
90a5c9 |
int capacity,
|
|
Packit |
90a5c9 |
request_rec **pr);
|
|
Packit |
90a5c9 |
void h2_mplx_req_engine_done(struct h2_req_engine *ngn, conn_rec *r_conn,
|
|
Packit |
90a5c9 |
apr_status_t status);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif /* defined(__mod_h2__h2_mplx__) */
|