Apache HTTPD
Macros | Functions
h2_bucket_beam.c File Reference
#include <apr_lib.h>
#include <apr_atomic.h>
#include <apr_strings.h>
#include <apr_time.h>
#include <apr_buckets.h>
#include <apr_thread_mutex.h>
#include <apr_thread_cond.h>
#include <httpd.h>
#include <http_protocol.h>
#include <http_request.h>
#include <http_log.h>
#include "h2_private.h"
#include "h2_conn_ctx.h"
#include "h2_headers.h"
#include "h2_util.h"
#include "h2_bucket_beam.h"

Go to the source code of this file.

Macros

#define H2_BLIST_INIT(b)   APR_RING_INIT(&(b)->list, apr_bucket, link);
 
#define H2_BLIST_SENTINEL(b)   APR_RING_SENTINEL(&(b)->list, apr_bucket, link)
 
#define H2_BLIST_EMPTY(b)   APR_RING_EMPTY(&(b)->list, apr_bucket, link)
 
#define H2_BLIST_FIRST(b)   APR_RING_FIRST(&(b)->list)
 
#define H2_BLIST_LAST(b)   APR_RING_LAST(&(b)->list)
 
#define H2_BLIST_INSERT_HEAD(b, e)
 
#define H2_BLIST_INSERT_TAIL(b, e)
 
#define H2_BLIST_CONCAT(a, b)
 
#define H2_BLIST_PREPEND(a, b)
 
#define H2_BEAM_LOG(beam, c, level, rv, msg, bb)
 

Functions

static int buffer_is_empty (h2_bucket_beam *beam)
 
static apr_off_t get_buffered_data_len (h2_bucket_beam *beam)
 
static int h2_blist_count (h2_blist *blist)
 
static int bucket_is_mmap (apr_bucket *b)
 
static apr_off_t bucket_mem_used (apr_bucket *b)
 
static int report_consumption (h2_bucket_beam *beam, int locked)
 
static apr_size_t calc_buffered (h2_bucket_beam *beam)
 
static void purge_consumed_buckets (h2_bucket_beam *beam)
 
static void purge_eor_buckets (h2_bucket_beam *beam)
 
static apr_size_t calc_space_left (h2_bucket_beam *beam)
 
static apr_status_t wait_not_empty (h2_bucket_beam *beam, conn_rec *c, apr_read_type_e block)
 
static apr_status_t wait_not_full (h2_bucket_beam *beam, conn_rec *c, apr_read_type_e block, apr_size_t *pspace_left)
 
static void h2_blist_cleanup (h2_blist *bl)
 
static void beam_shutdown (h2_bucket_beam *beam, apr_shutdown_how_e how)
 
static apr_status_t beam_cleanup (void *data)
 
apr_status_t h2_beam_destroy (h2_bucket_beam *beam, conn_rec *c)
 
apr_status_t h2_beam_create (h2_bucket_beam **pbeam, conn_rec *from, apr_pool_t *pool, int id, const char *tag, apr_size_t max_buf_size, apr_interval_time_t timeout)
 
void h2_beam_buffer_size_set (h2_bucket_beam *beam, apr_size_t buffer_size)
 
void h2_beam_set_copy_files (h2_bucket_beam *beam, int enabled)
 
apr_size_t h2_beam_buffer_size_get (h2_bucket_beam *beam)
 
apr_interval_time_t h2_beam_timeout_get (h2_bucket_beam *beam)
 
void h2_beam_timeout_set (h2_bucket_beam *beam, apr_interval_time_t timeout)
 
void h2_beam_abort (h2_bucket_beam *beam, conn_rec *c)
 
void h2_beam_close (h2_bucket_beam *beam, conn_rec *c)
 
static apr_status_t append_bucket (h2_bucket_beam *beam, apr_bucket_brigade *bb, apr_read_type_e block, apr_size_t *pspace_left, apr_off_t *pwritten)
 
apr_status_t h2_beam_send (h2_bucket_beam *beam, conn_rec *from, apr_bucket_brigade *sender_bb, apr_read_type_e block, apr_off_t *pwritten)
 
apr_status_t h2_beam_receive (h2_bucket_beam *beam, conn_rec *to, apr_bucket_brigade *bb, apr_read_type_e block, apr_off_t readbytes)
 
void h2_beam_on_consumed (h2_bucket_beam *beam, h2_beam_io_callback *io_cb, void *ctx)
 
void h2_beam_on_received (h2_bucket_beam *beam, h2_beam_ev_callback *recv_cb, void *ctx)
 
void h2_beam_on_eagain (h2_bucket_beam *beam, h2_beam_ev_callback *eagain_cb, void *ctx)
 
void h2_beam_on_send (h2_bucket_beam *beam, h2_beam_ev_callback *send_cb, void *ctx)
 
void h2_beam_on_was_empty (h2_bucket_beam *beam, h2_beam_ev_callback *was_empty_cb, void *ctx)
 
apr_off_t h2_beam_get_buffered (h2_bucket_beam *beam)
 
apr_off_t h2_beam_get_mem_used (h2_bucket_beam *beam)
 
int h2_beam_empty (h2_bucket_beam *beam)
 
int h2_beam_report_consumption (h2_bucket_beam *beam)
 
int h2_beam_is_complete (h2_bucket_beam *beam)
 

Macro Definition Documentation

◆ H2_BEAM_LOG

#define H2_BEAM_LOG (   beam,
  c,
  level,
  rv,
  msg,
  bb 
)
Value:
do { \
if (APLOG_C_IS_LEVEL((c),(level))) { \
char buffer[4 * 1024]; \
apr_size_t len, bmax = sizeof(buffer)/sizeof(buffer[0]); \
len = bb? h2_util_bb_print(buffer, bmax, "", "", bb) : 0; \
ap_log_cerror(APLOG_MARK, (level), rv, (c), \
"BEAM[%s,%s%sdata=%ld,buckets(send/consumed)=%d/%d]: %s %s", \
(beam)->name, \
(beam)->aborted? "aborted," : "", \
buffer_is_empty(beam)? "empty," : "", \
h2_blist_count(&(beam)->buckets_to_send), \
h2_blist_count(&(beam)->buckets_consumed), \
(msg), len? buffer : ""); \
} \
} while (0)
const char apr_size_t len
Definition ap_regex.h:187
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_C_IS_LEVEL(c, level)
Definition http_log.h:225
apr_size_t size
char * buffer
apr_vformatter_buff_t * c
Definition apr_lib.h:175
static int h2_blist_count(h2_blist *blist)
static int buffer_is_empty(h2_bucket_beam *beam)
static apr_off_t get_buffered_data_len(h2_bucket_beam *beam)
apr_size_t h2_util_bb_print(char *buffer, apr_size_t bmax, const char *tag, const char *sep, apr_bucket_brigade *bb)
Definition h2_util.c:1290
char * name

Definition at line 73 of file h2_bucket_beam.c.

◆ H2_BLIST_CONCAT

#define H2_BLIST_CONCAT (   a,
  b 
)
Value:
do { \
APR_RING_CONCAT(&(a)->list, &(b)->list, apr_bucket, link); \
} while (0)
apr_bucket apr_bucket_brigade * a
const apr_array_header_t * list
Definition apr_cstr.h:105
apr_pool_t * b
Definition apr_pools.h:529

Definition at line 50 of file h2_bucket_beam.c.

◆ H2_BLIST_EMPTY

#define H2_BLIST_EMPTY (   b)    APR_RING_EMPTY(&(b)->list, apr_bucket, link)

Definition at line 39 of file h2_bucket_beam.c.

◆ H2_BLIST_FIRST

#define H2_BLIST_FIRST (   b)    APR_RING_FIRST(&(b)->list)

Definition at line 40 of file h2_bucket_beam.c.

◆ H2_BLIST_INIT

#define H2_BLIST_INIT (   b)    APR_RING_INIT(&(b)->list, apr_bucket, link);

Definition at line 37 of file h2_bucket_beam.c.

◆ H2_BLIST_INSERT_HEAD

#define H2_BLIST_INSERT_HEAD (   b,
  e 
)
Value:
do { \
} while (0)
apr_bucket * e

Definition at line 42 of file h2_bucket_beam.c.

◆ H2_BLIST_INSERT_TAIL

#define H2_BLIST_INSERT_TAIL (   b,
  e 
)
Value:
do { \
} while (0)

Definition at line 46 of file h2_bucket_beam.c.

◆ H2_BLIST_LAST

#define H2_BLIST_LAST (   b)    APR_RING_LAST(&(b)->list)

Definition at line 41 of file h2_bucket_beam.c.

◆ H2_BLIST_PREPEND

#define H2_BLIST_PREPEND (   a,
  b 
)
Value:
do { \
APR_RING_PREPEND(&(a)->list, &(b)->list, apr_bucket, link); \
} while (0)

Definition at line 53 of file h2_bucket_beam.c.

◆ H2_BLIST_SENTINEL

#define H2_BLIST_SENTINEL (   b)    APR_RING_SENTINEL(&(b)->list, apr_bucket, link)

Definition at line 38 of file h2_bucket_beam.c.

Function Documentation

◆ append_bucket()

static apr_status_t append_bucket ( h2_bucket_beam beam,
apr_bucket_brigade bb,
apr_read_type_e  block,
apr_size_t pspace_left,
apr_off_t pwritten 
)
static

Definition at line 420 of file h2_bucket_beam.c.

◆ beam_cleanup()

static apr_status_t beam_cleanup ( void *  data)
static

Definition at line 281 of file h2_bucket_beam.c.

◆ beam_shutdown()

static void beam_shutdown ( h2_bucket_beam beam,
apr_shutdown_how_e  how 
)
static

Definition at line 260 of file h2_bucket_beam.c.

◆ bucket_is_mmap()

static int bucket_is_mmap ( apr_bucket b)
static

Definition at line 92 of file h2_bucket_beam.c.

◆ bucket_mem_used()

static apr_off_t bucket_mem_used ( apr_bucket b)
static

Definition at line 102 of file h2_bucket_beam.c.

◆ buffer_is_empty()

static int buffer_is_empty ( h2_bucket_beam beam)
static

Definition at line 190 of file h2_bucket_beam.c.

◆ calc_buffered()

static apr_size_t calc_buffered ( h2_bucket_beam beam)
static

Definition at line 133 of file h2_bucket_beam.c.

◆ calc_space_left()

static apr_size_t calc_space_left ( h2_bucket_beam beam)
static

Definition at line 181 of file h2_bucket_beam.c.

◆ get_buffered_data_len()

static apr_off_t get_buffered_data_len ( h2_bucket_beam beam)
static

Definition at line 804 of file h2_bucket_beam.c.

◆ h2_beam_abort()

void h2_beam_abort ( h2_bucket_beam beam,
conn_rec c 
)

Abort the beam, either from receiving or sending side.

Parameters
beamthe beam to abort
cthe connection the caller is working with

Definition at line 376 of file h2_bucket_beam.c.

◆ h2_beam_buffer_size_get()

apr_size_t h2_beam_buffer_size_get ( h2_bucket_beam beam)

Definition at line 349 of file h2_bucket_beam.c.

◆ h2_beam_buffer_size_set()

void h2_beam_buffer_size_set ( h2_bucket_beam beam,
apr_size_t  buffer_size 
)

Set/get the maximum buffer size for beam data (memory footprint).

Definition at line 335 of file h2_bucket_beam.c.

◆ h2_beam_close()

void h2_beam_close ( h2_bucket_beam beam,
conn_rec c 
)

Close the beam. Make certain an EOS is sent.

Parameters
beamthe beam to abort
cthe connection the caller is working with

Definition at line 402 of file h2_bucket_beam.c.

◆ h2_beam_create()

apr_status_t h2_beam_create ( h2_bucket_beam **  pbeam,
conn_rec from,
apr_pool_t pool,
int  id,
const char tag,
apr_size_t  buffer_size,
apr_interval_time_t  timeout 
)

Creates a new bucket beam for transfer of buckets across threads.

The pool the beam is created with will be protected by the given mutex and will be used in multiple threads. It needs a pool allocator that is only used inside that same mutex.

Parameters
pbeamwill hold the created beam on return
c_fromconnection from which buchets are sent
poolpool owning the beam, beam will cleanup when pool released
ididentifier of the beam
tagtag identifying beam for logging
buffer_sizemaximum memory footprint of buckets buffered in beam, or 0 for no limitation
timeouttimeout for blocking operations

Definition at line 300 of file h2_bucket_beam.c.

◆ h2_beam_destroy()

apr_status_t h2_beam_destroy ( h2_bucket_beam beam,
conn_rec c 
)

Destroys the beam immediately without cleanup.

Definition at line 290 of file h2_bucket_beam.c.

◆ h2_beam_empty()

int h2_beam_empty ( h2_bucket_beam beam)

Determine if beam is empty.

Definition at line 843 of file h2_bucket_beam.c.

◆ h2_beam_get_buffered()

apr_off_t h2_beam_get_buffered ( h2_bucket_beam beam)

Get the amount of bytes currently buffered in the beam (unread).

Definition at line 818 of file h2_bucket_beam.c.

◆ h2_beam_get_mem_used()

apr_off_t h2_beam_get_mem_used ( h2_bucket_beam beam)

Get the memory used by the buffered buckets, approximately.

Definition at line 828 of file h2_bucket_beam.c.

◆ h2_beam_is_complete()

int h2_beam_is_complete ( h2_bucket_beam beam)
Returns
!= 0 iff beam has been closed or has an EOS bucket buffered waiting to be received.

Definition at line 863 of file h2_bucket_beam.c.

◆ h2_beam_on_consumed()

void h2_beam_on_consumed ( h2_bucket_beam beam,
h2_beam_io_callback io_cb,
void *  ctx 
)

Register a callback to be invoked on the sender side with the amount of bytes that have been consumed by the receiver, since the last callback invocation or reset.

Parameters
beamthe beam to set the callback on
io_cbthe callback or NULL, called on sender with bytes consumed
ctxthe context to use in callback invocation

Call from the sender side, io callbacks invoked on sender side, ev callback from any side.

Definition at line 758 of file h2_bucket_beam.c.

◆ h2_beam_on_eagain()

void h2_beam_on_eagain ( h2_bucket_beam beam,
h2_beam_ev_callback eagain_cb,
void *  ctx 
)

Register a callback to be invoked on the receiver side whenever APR_EAGAIN is being returned in h2_beam_receive().

Parameters
beamthe beam to set the callback on
egain_cbthe callback or NULL, called before APR_EAGAIN is returned
ctxthe context to use in callback invocation

Definition at line 776 of file h2_bucket_beam.c.

◆ h2_beam_on_received()

void h2_beam_on_received ( h2_bucket_beam beam,
h2_beam_ev_callback recv_cb,
void *  ctx 
)

Register a callback to be invoked on the receiver side whenever buckets have been transfered in a h2_beam_receive() call.

Parameters
beamthe beam to set the callback on
recv_cbthe callback or NULL, called when buckets are received
ctxthe context to use in callback invocation

Definition at line 767 of file h2_bucket_beam.c.

◆ h2_beam_on_send()

void h2_beam_on_send ( h2_bucket_beam beam,
h2_beam_ev_callback on_send_cb,
void *  ctx 
)

Register a call back from the sender side to be invoked when send has added buckets to the beam. Unregister by passing a NULL on_send_cb.

Parameters
beamthe beam to set the callback on
on_send_cbthe callback to invoke after buckets were added
ctxthe context to use in callback invocation

Definition at line 785 of file h2_bucket_beam.c.

◆ h2_beam_on_was_empty()

void h2_beam_on_was_empty ( h2_bucket_beam beam,
h2_beam_ev_callback was_empty_cb,
void *  ctx 
)

Register a call back from the sender side to be invoked when send has added to a previously empty beam. Unregister by passing a NULL was_empty_cb.

Parameters
beamthe beam to set the callback on
was_empty_cbthe callback to invoke on blocked send
ctxthe context to use in callback invocation

Definition at line 794 of file h2_bucket_beam.c.

◆ h2_beam_receive()

apr_status_t h2_beam_receive ( h2_bucket_beam beam,
conn_rec to,
apr_bucket_brigade bb,
apr_read_type_e  block,
apr_off_t  readbytes 
)

Receive buckets from the beam into the given brigade. The caller is operating on connection to.

Parameters
beamthe beam to receive buckets from
tothe connection the receiver is working with
bbthe bucket brigade to append to
blockif the read should block when buckets are unavailable
readbytesthe amount of data the receiver wants
Returns
APR_SUCCESS when buckets were appended APR_EAGAIN on non-blocking read when no buckets are available APR_TIMEUP on blocking reads that time out APR_ECONNABORTED when beam has been aborted

Definition at line 596 of file h2_bucket_beam.c.

◆ h2_beam_report_consumption()

int h2_beam_report_consumption ( h2_bucket_beam beam)

Call any registered consumed handler, if any changes have happened since the last invocation.

Returns
!=0 iff a handler has been called

Needs to be invoked from the sending side.

Definition at line 853 of file h2_bucket_beam.c.

◆ h2_beam_send()

apr_status_t h2_beam_send ( h2_bucket_beam beam,
conn_rec from,
apr_bucket_brigade bb,
apr_read_type_e  block,
apr_off_t pwritten 
)

Send buckets from the given brigade through the beam. This can block of the amount of bucket data is above the buffer limit.

Parameters
beamthe beam to add buckets to
fromthe connection the sender operates on, must be the same as used to create the beam
bbthe brigade to take buckets from
blockif the sending should block when the buffer is full
pwrittenon return, contains the number of data bytes sent
Returns
APR_SUCCESS when buckets were added to the beam. This can be a partial transfer and other buckets may still remain in bb APR_EAGAIN on non-blocking send when the buffer is full APR_TIMEUP on blocking semd that time out APR_ECONNABORTED when beam has been aborted

Definition at line 530 of file h2_bucket_beam.c.

◆ h2_beam_set_copy_files()

void h2_beam_set_copy_files ( h2_bucket_beam beam,
int  enabled 
)

Switch copying of file buckets on/off.

Definition at line 342 of file h2_bucket_beam.c.

◆ h2_beam_timeout_get()

apr_interval_time_t h2_beam_timeout_get ( h2_bucket_beam beam)

Definition at line 359 of file h2_bucket_beam.c.

◆ h2_beam_timeout_set()

void h2_beam_timeout_set ( h2_bucket_beam beam,
apr_interval_time_t  timeout 
)

Set/get the timeout for blocking sebd/receive operations.

Definition at line 369 of file h2_bucket_beam.c.

◆ h2_blist_cleanup()

static void h2_blist_cleanup ( h2_blist bl)
static

Definition at line 250 of file h2_bucket_beam.c.

◆ h2_blist_count()

static int h2_blist_count ( h2_blist blist)
static

Definition at line 61 of file h2_bucket_beam.c.

◆ purge_consumed_buckets()

static void purge_consumed_buckets ( h2_bucket_beam beam)
static

Definition at line 153 of file h2_bucket_beam.c.

◆ purge_eor_buckets()

static void purge_eor_buckets ( h2_bucket_beam beam)
static

Definition at line 170 of file h2_bucket_beam.c.

◆ report_consumption()

static int report_consumption ( h2_bucket_beam beam,
int  locked 
)
static

Definition at line 113 of file h2_bucket_beam.c.

◆ wait_not_empty()

static apr_status_t wait_not_empty ( h2_bucket_beam beam,
conn_rec c,
apr_read_type_e  block 
)
static

Definition at line 195 of file h2_bucket_beam.c.

◆ wait_not_full()

static apr_status_t wait_not_full ( h2_bucket_beam beam,
conn_rec c,
apr_read_type_e  block,
apr_size_t pspace_left 
)
static

Definition at line 221 of file h2_bucket_beam.c.