repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
zap
github_2023
zigzap
c
http1_on_path
static int http1_on_path(http1_parser_s *parser, char *path, size_t len) { http1_pr2handle(parser2http(parser)).path = fiobj_str_new(path, len); parser2http(parser)->header_size += len; return 0; }
/** called when a request path (excluding query) is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L589-L593
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_query
static int http1_on_query(http1_parser_s *parser, char *query, size_t len) { http1_pr2handle(parser2http(parser)).query = fiobj_str_new(query, len); parser2http(parser)->header_size += len; return 0; }
/** called when a request path (excluding query) is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L596-L600
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_version
static int http1_on_version(http1_parser_s *parser, char *version, size_t len) { http1_pr2handle(parser2http(parser)).version = fiobj_str_new(version, len); parser2http(parser)->header_size += len; /* start counting - occurs on the first line of both requests and responses */ #if FIO_HTTP_EXACT_LOGGING clock_gett...
/** called when a the HTTP/1.x version is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L602-L613
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_header
static int http1_on_header(http1_parser_s *parser, char *name, size_t name_len, char *data, size_t data_len) { FIOBJ sym; FIOBJ obj; if (!http1_pr2handle(parser2http(parser)).headers) { FIO_LOG_ERROR("(http1 parse ordering error) missing HashMap for header " "%s: %...
/** called when a header is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L615-L643
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_body_chunk
static int http1_on_body_chunk(http1_parser_s *parser, char *data, size_t data_len) { if (parser->state.content_length > (ssize_t)parser2http(parser)->p.settings->max_body_size || parser->state.read > (ssize_t)parser2http(parser)->p.settings->max_body_size) { ...
/** called when a body chunk is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L645-L664
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_error
static int http1_on_error(http1_parser_s *parser) { if (parser2http(parser)->close) return -1; FIO_LOG_DEBUG("HTTP parser error."); fio_close(parser2http(parser)->p.uuid); return -1; }
/** called when a protocol error occurred. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L667-L673
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_consume_data
static inline void http1_consume_data(intptr_t uuid, http1pr_s *p) { if (fio_pending(uuid) > 4) { goto throttle; } ssize_t i = 0; size_t org_len = p->buf_len; int pipeline_limit = 8; if (!p->buf_len) return; do { i = http1_parse(&p->parser, p->buf + (org_len - p->buf_len), p->buf_len); p->...
/* ***************************************************************************** Connection Callbacks ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L679-L719
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_data
static void http1_on_data(intptr_t uuid, fio_protocol_s *protocol) { http1pr_s *p = (http1pr_s *)protocol; if (p->stop) { fio_suspend(uuid); return; } ssize_t i = 0; if (HTTP_MAX_HEADER_LENGTH - p->buf_len) i = fio_read(uuid, p->buf + p->buf_len, HTTP_MAX_HEADER_LENGTH - p->buf_le...
/** called when a data is available, but will not run concurrently */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L722-L736
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_close
static void http1_on_close(intptr_t uuid, fio_protocol_s *protocol) { http1_destroy(protocol); (void)uuid; }
/** called when the connection was closed, but will not run concurrently */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L739-L742
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_ready
static void http1_on_ready(intptr_t uuid, fio_protocol_s *protocol) { /* resume slow clients from suspension */ http1pr_s *p = (http1pr_s *)protocol; if (p->stop & 4) { p->stop ^= 4; /* flip back the bit, so it's zero */ fio_force_event(uuid, FIO_EVENT_ON_DATA); } (void)protocol; }
/** called when the connection was closed, but will not run concurrently */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L745-L753
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_data_first_time
static void http1_on_data_first_time(intptr_t uuid, fio_protocol_s *protocol) { http1pr_s *p = (http1pr_s *)protocol; ssize_t i; i = fio_read(uuid, p->buf + p->buf_len, HTTP_MAX_HEADER_LENGTH - p->buf_len); if (i <= 0) return; p->buf_len += i; /* ensure future reads skip this first time HTTP/2.0 test...
/** called when a data is available for the first time */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L756-L776
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_destroy
void http1_destroy(fio_protocol_s *pr) { http1pr_s *p = (http1pr_s *)pr; http1_pr2handle(p).status = 0; http_s_destroy(&http1_pr2handle(p), 0); fio_free(p); // FIO_LOG_DEBUG("Deallocated HTTP/1.1 protocol at. %p", (void *)p); }
/** Manually destroys the HTTP1 protocol object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L816-L822
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1pr_status2str
static fio_str_info_s http1pr_status2str(uintptr_t status) { static fio_str_info_s status2str[] = { HTTP_SET_STATUS_STR(100, "Continue"), HTTP_SET_STATUS_STR(101, "Switching Protocols"), HTTP_SET_STATUS_STR(102, "Processing"), HTTP_SET_STATUS_STR(103, "Early Hints"), HTTP_SET_STATUS_STR(...
// #undef HTTP_SET_STATUS_STR // clang-format on
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L833-L908
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_on_request_handler______internal
void http_on_request_handler______internal(http_s *h, http_settings_s *settings) { if (!http_upgrade_hash) http_upgrade_hash = fiobj_hash_string("upgrade", 7); h->udata = settings->udata; static uint64_t host_hash = 0; if (!host_hash) host_hash = fiobj_hash_st...
/** Use this function to handle HTTP requests.*/
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http_internal.c#L17-L75
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_send_error2
int http_send_error2(size_t error, intptr_t uuid, http_settings_s *settings) { if (!uuid || !settings || !error) return -1; fio_protocol_s *pr = http1_new(uuid, settings, NULL, 0); http_s *r = fio_malloc(sizeof(*r)); FIO_ASSERT(pr, "Couldn't allocate response object for error report.") http_s_new(r, (http...
/* ***************************************************************************** Internal helpers ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http_internal.c#L96-L106
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
clear_subscriptions
static inline void clear_subscriptions(ws_s *ws) { fio_lock(&ws->sub_lock); while (fio_ls_any(&ws->subscriptions)) { fio_unsubscribe(fio_ls_pop(&ws->subscriptions)); } fio_unlock(&ws->sub_lock); }
/* ***************************************************************************** Create/Destroy the websocket subscription objects ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L139-L145
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_on_unwrapped
static void websocket_on_unwrapped(void *ws_p, void *msg, uint64_t len, char first, char last, char text, unsigned char rsv) { ws_s *ws = ws_p; if (last && first) { ws->on_message(ws, (fio_str_info_s){.data = msg, .len = len}, ...
/* ***************************************************************************** Callbacks - Required functions for websocket_parser.h ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L151-L172
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_optimize_free
static void websocket_optimize_free(fio_msg_s *msg, void *metadata) { fiobj_free((FIOBJ)metadata); (void)msg; }
/* ***************************************************************************** Multi-client broadcast optimizations ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L409-L412
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_optimize4broadcasts
void websocket_optimize4broadcasts(intptr_t type, int enable) { static intptr_t generic = 0; static intptr_t text = 0; static intptr_t binary = 0; fio_msg_metadata_s (*callback)(fio_str_info_s, fio_str_info_s, uint8_t); intptr_t *counter; switch ((0 - type)) { case (0 - WEBSOCKET_OPTIMIZE_PUBSUB): cou...
/** * Enables (or disables) broadcast optimizations. * * When using WebSocket pub/sub system is originally optimized for either * non-direct transmission (messages are handled by callbacks) or direct * transmission to 1-3 clients per channel (on average), meaning that the * majority of the messages are meant for ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L488-L519
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_unsubscribe
void websocket_unsubscribe(ws_s *ws, uintptr_t subscription_id) { fio_unsubscribe((subscription_s *)((fio_ls_s *)subscription_id)->obj); fio_lock(&ws->sub_lock); fio_ls_remove((fio_ls_s *)subscription_id); fio_unlock(&ws->sub_lock); (void)ws; }
/** * Unsubscribes from a channel. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L682-L689
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_uuid
intptr_t websocket_uuid(ws_s *ws) { return ws->fd; }
/** Returns the the process specific connection's UUID (see `libsock`). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L699-L699
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_is_client
uint8_t websocket_is_client(ws_s *ws) { return ws->is_client; }
/** * Returns 1 if the WebSocket connection is in Client mode (connected to a * remote server) and 0 if the connection is in Server mode (a connection * established using facil.io's HTTP server). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L714-L714
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_write
int websocket_write(ws_s *ws, fio_str_info_s msg, uint8_t is_text) { if (fio_is_valid(ws->fd)) { websocket_write_impl(ws->fd, msg.data, msg.len, is_text, 1, 1, ws->is_client); return 0; } return -1; }
/** Writes data to the websocket. Returns -1 on failure (0 on success). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L717-L724
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
websocket_close
void websocket_close(ws_s *ws) { fio_write2(ws->fd, .data.buffer = "\x88\x00", .length = 2, .after.dealloc = FIO_DEALLOC_NOOP); fio_close(ws->fd); return; }
/** Closes a websocket connection. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/websockets.c#L726-L731
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_memcpy
static inline void fio_memcpy(void *__restrict dest_, void *__restrict src_, size_t units) { #if __SIZEOF_INT128__ == 9 /* a 128bit type exists... but tests favor 64bit */ register __uint128_t *dest = dest_; register __uint128_t *src = src_; #elif SIZE_MAX == 0xFFFFFFFFFFFFFFFF /* 64 b...
/* ***************************************************************************** Memory Copying by 16 byte units ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L58-L129
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
spn_trylock
static inline int spn_trylock(spn_lock_i *lock) { return SPN_LOCK_BUILTIN(lock, 1); }
/** returns 1 and 0 if the lock was successfully aquired (TRUE == FAIL). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L194-L196
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
spn_unlock
static inline __attribute__((unused)) int spn_unlock(spn_lock_i *lock) { return SPN_LOCK_BUILTIN(lock, 0); }
/** Releases a lock. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L199-L201
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
spn_is_locked
static inline __attribute__((unused)) int spn_is_locked(spn_lock_i *lock) { __asm__ volatile("" ::: "memory"); return *lock; }
/** returns a lock's state (non 0 == Busy). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L204-L207
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
spn_lock
static inline __attribute__((unused)) void spn_lock(spn_lock_i *lock) { while (spn_trylock(lock)) { reschedule_thread(); } }
/** Busy waits for the lock. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L210-L214
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
sys_free
static inline void sys_free(void *mem, size_t len) { munmap(mem, len); }
/* frees memory using `munmap`. requires exact, page aligned, `len` */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L265-L265
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
sys_round_size
static inline size_t sys_round_size(size_t size) { return (size & (~4095)) + (4096 * (!!(size & 4095))); }
/** Rounds up any size to the nearest page alignment (assumes 4096 bytes per * page) */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L300-L302
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_malloc_after_fork
void fio_malloc_after_fork(void) { arena_last_used = NULL; if (!arenas) { return; } memory.lock = SPN_LOCK_INIT; for (size_t i = 0; i < memory.cores; ++i) { arenas[i].lock = SPN_LOCK_INIT; } }
/** Clears any memory locks, in case of a system call to `fork`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L371-L380
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
block_free
static inline void block_free(block_s *blk) { if (spn_sub(&blk->ref, 1)) return; if (spn_add(&memory.count, 1) > (intptr_t)(FIO_MEM_MAX_BLOCKS_PER_CORE * memory.cores)) { /* TODO: return memory to the system */ spn_sub(&memory.count, 1); sys_free(blk, FIO_MEMORY_BLOCK_SIZE); return; } ...
/* intializes the block header for an available block of memory. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L404-L420
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_mem_init
static void __attribute__((constructor)) fio_mem_init(void) { if (arenas) return; #ifdef _SC_NPROCESSORS_ONLN ssize_t cpu_count = sysconf(_SC_NPROCESSORS_ONLN); #else #warning Dynamic CPU core count is unavailable - assuming 8 cores for memory allocation pools. ssize_t cpu_count = 8; /* fallback */ #endif ...
/* ***************************************************************************** Library Initialization (initialize arenas and allocate a block for each CPU) ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/legacy/fio_mem.c#L520-L546
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_internal_reset
static inline void redis_internal_reset(struct redis_engine_internal_s *i) { i->buf_pos = 0; i->parser = (resp_parser_s){.obj_countdown = 0, .expecting = 0}; fiobj_free((FIOBJ)fio_ct_if(i->ary == FIOBJ_INVALID, (uintptr_t)i->str, (uintptr_t)i->ary)); i->str = FIOBJ_INVALID; i->ar...
/* releases any resources used by an internal engine*/
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L72-L82
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_free
static inline void redis_free(redis_engine_s *r) { if (fio_atomic_sub(&r->ref, 1)) return; FIO_LOG_DEBUG("freeing redis engine for %s:%s", r->address, r->port); redis_internal_reset(&r->pub_data); redis_internal_reset(&r->sub_data); fiobj_free(r->last_ch); while (fio_ls_embd_any(&r->queue)) { fio_fr...
/** cleans up and frees the engine data. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L85-L103
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj2resp___internal
inline static void fiobj2resp___internal(FIOBJ dest, FIOBJ obj) { fio_str_info_s s; switch (FIOBJ_TYPE(obj)) { case FIOBJ_T_NULL: fiobj_str_write(dest, "$-1\r\n", 5); break; case FIOBJ_T_ARRAY: fiobj_str_write(dest, "*", 1); fiobj_str_write_i(dest, fiobj_ary_count(obj)); fiobj_str_write(dest...
/* ***************************************************************************** Simple RESP formatting ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L109-L153
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj2resp
static FIOBJ fiobj2resp(FIOBJ dest, FIOBJ obj) { fiobj_each2(obj, fiobj2resp_task, (void *)dest); return dest; }
/** * Converts FIOBJ objects into a RESP string (client mode). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L165-L168
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj2resp_tmp
static inline FIOBJ fiobj2resp_tmp(FIOBJ obj) { return fiobj2resp(fiobj_str_tmp(), obj); }
/** * Converts FIOBJ objects into a RESP string (client mode). * * Don't call `fiobj_free`, object will self-destruct. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L175-L177
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_parser_error
static int resp_on_parser_error(resp_parser_s *parser) { struct redis_engine_internal_s *i = parser2data(parser); FIO_LOG_ERROR("(redis) parser error - attempting to restart connection.\n"); fio_close(i->uuid); return -1; }
/* ***************************************************************************** RESP parser callbacks ***************************************************************************** */ /** a local static callback, called when a parser / protocol error occurs. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L184-L189
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_message
static int resp_on_message(resp_parser_s *parser) { struct redis_engine_internal_s *i = parser2data(parser); FIOBJ msg = i->ary ? i->ary : i->str; i->on_message(i, msg); /* cleanup */ fiobj_free(msg); i->ary = FIOBJ_INVALID; i->str = FIOBJ_INVALID; return 0; }
/** a local static callback, called when the RESP message is complete. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L192-L201
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_add_obj
static inline void resp_add_obj(struct redis_engine_internal_s *dest, FIOBJ o) { if (dest->ary) { fiobj_ary_push(dest->ary, o); --dest->ary_count; if (!dest->ary_count && dest->nesting) { FIOBJ tmp = fiobj_ary_shift(dest->ary); dest->ary_count = fiobj_obj2num(tmp); fiobj_free(tmp); ...
/** a local helper to add parsed objects to the data store. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L204-L217
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_number
static int resp_on_number(resp_parser_s *parser, int64_t num) { struct redis_engine_internal_s *data = parser2data(parser); resp_add_obj(data, fiobj_num_new(num)); return 0; }
/** a local static callback, called when a Number object is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L220-L224
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_okay
static int resp_on_okay(resp_parser_s *parser) { struct redis_engine_internal_s *data = parser2data(parser); resp_add_obj(data, fiobj_true()); return 0; }
/** a local static callback, called when a OK message is received. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L226-L230
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_null
static int resp_on_null(resp_parser_s *parser) { struct redis_engine_internal_s *data = parser2data(parser); resp_add_obj(data, fiobj_null()); return 0; }
/** a local static callback, called when NULL is received. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L232-L236
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_start_string
static int resp_on_start_string(resp_parser_s *parser, size_t str_len) { struct redis_engine_internal_s *data = parser2data(parser); resp_add_obj(data, fiobj_str_buf(str_len)); return 0; }
/** * a local static callback, called when a String should be allocated. * * `str_len` is the expected number of bytes that will fill the final string * object, without any NUL byte marker (the string might be binary). * * If this function returns any value besides 0, parsing is stopped. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L246-L250
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_string_chunk
static int resp_on_string_chunk(resp_parser_s *parser, void *data, size_t len) { struct redis_engine_internal_s *i = parser2data(parser); fiobj_str_write(i->str, data, len); return 0; }
/** a local static callback, called as String objects are streamed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L252-L256
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_end_string
static int resp_on_end_string(resp_parser_s *parser) { return 0; (void)parser; }
/** a local static callback, called when a String object had finished * streaming. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L260-L263
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_err_msg
static int resp_on_err_msg(resp_parser_s *parser, void *data, size_t len) { struct redis_engine_internal_s *i = parser2data(parser); resp_add_obj(i, fiobj_str_new(data, len)); return 0; }
/** a local static callback, called an error message is received. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L266-L270
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_start_array
static int resp_on_start_array(resp_parser_s *parser, size_t array_len) { struct redis_engine_internal_s *i = parser2data(parser); if (i->ary) { ++i->nesting; FIOBJ tmp = fiobj_ary_new2(array_len + 2); fiobj_ary_push(tmp, fiobj_num_new(i->ary_count)); fiobj_ary_push(tmp, fiobj_num_new(i->ary)); ...
/** * a local static callback, called when an Array should be allocated. * * `array_len` is the expected number of objects that will fill the Array * object. * * There's no `resp_on_end_array` callback since the RESP protocol assumes the * message is finished along with the Array (`resp_on_message` is called). ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L285-L298
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_perform_callback
static void redis_perform_callback(void *e, void *cmd_) { redis_commands_s *cmd = cmd_; FIOBJ reply = (FIOBJ)cmd->node.next; if (cmd->callback) cmd->callback(e, reply, cmd->udata); fiobj_free(reply); FIO_LOG_DEBUG("Handled: %s\n", cmd->cmd); fio_free(cmd); }
/* ***************************************************************************** Publication and Command Handling ***************************************************************************** */ /* the deferred callback handler */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L305-L313
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_send_next_command_unsafe
static void redis_send_next_command_unsafe(redis_engine_s *r) { if (!r->pub_sent && fio_ls_embd_any(&r->queue)) { r->pub_sent = 1; redis_commands_s *cmd = FIO_LS_EMBD_OBJ(redis_commands_s, node, r->queue.next); fio_write2(r->pub_data.uuid, .data.buffer = cmd->cmd, .length = cmd->cmd...
/* send command within lock, to ensure flag integrity */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L316-L326
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_attach_cmd
static void redis_attach_cmd(redis_engine_s *r, redis_commands_s *cmd) { fio_lock(&r->lock); fio_ls_embd_push(&r->queue, &cmd->node); redis_send_next_command_unsafe(r); fio_unlock(&r->lock); }
/* attach a command to the queue */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L329-L334
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_pub_message
static void resp_on_pub_message(struct redis_engine_internal_s *i, FIOBJ msg) { redis_engine_s *r = pub2redis(i); // #if DEBUG if (FIO_LOG_LEVEL >= FIO_LOG_LEVEL_DEBUG) { FIOBJ json = fiobj_obj2json(msg, 1); FIO_LOG_DEBUG("Redis reply:\n%s\n", fiobj_obj2cstr(json).data); fiobj_free(json); } // #en...
/** a local static callback, called when the RESP message is complete. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L337-L361
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
resp_on_sub_message
static void resp_on_sub_message(struct redis_engine_internal_s *i, FIOBJ msg) { redis_engine_s *r = sub2redis(i); /* subscriotion parser */ if (FIOBJ_TYPE(msg) != FIOBJ_T_ARRAY) { if (FIOBJ_TYPE(msg) != FIOBJ_T_STRING || fiobj_obj2cstr(msg).len != 4 || fiobj_obj2cstr(msg).data[0] != 'P') { FIO_L...
/* ***************************************************************************** Subscription Message Handling ***************************************************************************** */ /** a local static callback, called when the RESP message is complete. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L368-L398
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_data
static void redis_on_data(intptr_t uuid, fio_protocol_s *pr) { struct redis_engine_internal_s *internal = (struct redis_engine_internal_s *)pr; uint8_t *buf; if (internal->on_message == resp_on_sub_message) { buf = sub2redis(pr)->buf + REDIS_READ_BUFFER; } else { buf = pub2redis(pr)->buf; } ss...
/** Called when a data is available, but will not run concurrently */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L414-L434
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_close
static void redis_on_close(intptr_t uuid, fio_protocol_s *pr) { struct redis_engine_internal_s *internal = (struct redis_engine_internal_s *)pr; redis_internal_reset(internal); redis_engine_s *r; if (internal->on_message == resp_on_sub_message) { r = sub2redis(pr); fiobj_free(r->last_ch); r->l...
/** Called when the connection was closed, but will not run concurrently */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L437-L470
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_shutdown
static uint8_t redis_on_shutdown(intptr_t uuid, fio_protocol_s *pr) { fio_write2(uuid, .data.buffer = "*1\r\n$4\r\nQUIT\r\n", .length = 14, .after.dealloc = FIO_DEALLOC_NOOP); return 0; (void)pr; }
/** Called before the facil.io reactor is shut down. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L473-L478
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_sub_ping
static void redis_sub_ping(intptr_t uuid, fio_protocol_s *pr) { fio_write2(uuid, .data.buffer = "*1\r\n$4\r\nPING\r\n", .length = 14, .after.dealloc = FIO_DEALLOC_NOOP); (void)pr; }
/** Called on connection timeout. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L481-L485
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_pub_ping
static void redis_pub_ping(intptr_t uuid, fio_protocol_s *pr) { redis_engine_s *r = pub2redis(pr); if (fio_ls_embd_any(&r->queue)) { FIO_LOG_WARNING("(redis) Redis server unresponsive, disconnecting."); fio_close(uuid); return; } redis_commands_s *cmd = fio_malloc(sizeof(*cmd) + 15); *cmd = (redis...
/** Called on connection timeout. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L488-L499
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_auth
static void redis_on_auth(fio_pubsub_engine_s *e, FIOBJ reply, void *udata) { if (FIOBJ_TYPE_IS(reply, FIOBJ_T_TRUE)) { fio_str_info_s s = fiobj_obj2cstr(reply); FIO_LOG_WARNING("(redis) Authentication FAILED." " %.*s", (int)s.len, s.data); } (void)e; (void...
/* ***************************************************************************** Connecting to Redis ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L505-L514
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_subscribe_root
static void redis_on_subscribe_root(const fio_pubsub_engine_s *eng, fio_str_info_s channel, fio_match_fn match) { redis_engine_s *r = (redis_engine_s *)eng; if (r->sub_data.uuid != -1) { FIOBJ cmd = fiobj_str_buf(96 + channel.len); if (...
/* ***************************************************************************** Engine / Bridge Callbacks (Root Process) ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L589-L610
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_mock_subscribe_child
static void redis_on_mock_subscribe_child(const fio_pubsub_engine_s *eng, fio_str_info_s channel, fio_match_fn match) { /* do nothing, root process is notified about (un)subscriptions by facil.io */ (void)eng; (void)channel; (vo...
/* ***************************************************************************** Engine / Bridge Stub Callbacks (Child Process) ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L671-L678
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_internal_publish
static void redis_on_internal_publish(fio_msg_s *msg) { if (msg->channel.len < 8) return; /* internal error, unexpected data */ void *en = (void *)fio_str2u64(msg->channel.data); if (en != msg->udata1) return; /* should be delivered by a different engine */ /* step after the engine data */ msg->channe...
/* ***************************************************************************** Root Publication Handler ***************************************************************************** */ /* listens to filter -1 and publishes and messages */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L701-L714
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_forward_reply
static void redis_forward_reply(fio_pubsub_engine_s *e, FIOBJ reply, void *udata) { uint8_t *data = udata; fio_pubsub_engine_s *engine = (fio_pubsub_engine_s *)fio_str2u64(data + 0); void *callback = (void *)fio_str2u64(data + 8); if (engine != e || !callback) { FIO_LOG_DEBUG...
/* ***************************************************************************** Sending commands using the Root connection ***************************************************************************** */ /* callback from the Redis reply */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L721-L735
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_internal_cmd
static void redis_on_internal_cmd(fio_msg_s *msg) { // void*(void *)fio_str2u64(msg->msg.data); fio_pubsub_engine_s *engine = (fio_pubsub_engine_s *)fio_str2u64(msg->channel.data + 0); if (engine != msg->udata1) { return; } redis_commands_s *cmd = fio_malloc(sizeof(*cmd) + msg->msg.len + 1 + 28); ...
/* listens to channel -2 for commands that need to be sent (only ROOT) */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L738-L754
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_internal_reply
static void redis_on_internal_reply(fio_msg_s *msg) { fio_pubsub_engine_s *engine = (fio_pubsub_engine_s *)fio_str2u64(msg->channel.data + 0); if (engine != msg->udata1) { FIO_LOG_DEBUG("Redis reply not forwarded (engine mismatch: %p != %p)", (void *)engine, msg->udata1); return; }...
/* Listens on filter `-10 -getpid()` for incoming reply data */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L757-L772
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_engine_send
intptr_t redis_engine_send(fio_pubsub_engine_s *engine, FIOBJ command, void (*callback)(fio_pubsub_engine_s *e, FIOBJ reply, void *udata), void *udata) { if ((uintptr_t)engine < 4) { FIO_LOG_WARNING("(redis send) try...
/* publishes a Redis command to Root's filter -2 */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L775-L801
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_on_facil_start
static void redis_on_facil_start(void *r_) { redis_engine_s *r = r_; r->flag = 1; if (!fio_is_valid(r->sub_data.uuid)) { defer_redis_connect(r, &r->sub_data); } }
/* ***************************************************************************** Redis Engine Creation ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L807-L813
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
redis_engine_destroy
void redis_engine_destroy(fio_pubsub_engine_s *engine) { redis_engine_s *r = (redis_engine_s *)engine; r->flag = 0; fio_pubsub_detach(&r->en); fio_state_callback_remove(FIO_CALL_IN_CHILD, redis_on_engine_fork, r); fio_state_callback_remove(FIO_CALL_ON_SHUTDOWN, redis_on_facil_shutdown, r); fio_state_callbac...
/* ***************************************************************************** Redis Engine Destruction ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/redis/redis_engine.c#L945-L954
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
alpn_add
FIO_FUNC inline void alpn_add( fio_tls_s *tls, const char *protocol_name, void (*on_selected)(intptr_t uuid, void *udata_connection, void *udata_tls), void *udata_tls, void (*on_cleanup)(void *udata_tls)) { alpn_s tmp = { .name = FIO_STR_INIT_STATIC(protocol_name), .on_selected = on_selected, ...
/** Adds an ALPN data object to the ALPN "list" (set) */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L168-L185
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
alpn_select
FIO_FUNC inline void alpn_select(alpn_s *alpn, intptr_t uuid, void *udata_connection) { if (!alpn || !alpn->on_selected) return; alpn_task_s *t = fio_malloc(sizeof(*t)); *t = (alpn_task_s){ .alpn = *alpn, .uuid = uuid, .udata_connection = udata_connection, ...
/** Schedules the ALPN protocol callback. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L209-L221
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_destroy_context
static void fio_tls_destroy_context(fio_tls_s *tls) { /* TODO: Library specific implementation */ FIO_LOG_DEBUG("destroyed TLS context %p", (void *)tls); }
/* ***************************************************************************** SSL/TLS Context (re)-building - TODO: add implementation details ***************************************************************************** */ /** Called when the library specific data for the context should be destroyed */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L228-L231
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_build_context
static void fio_tls_build_context(fio_tls_s *tls) { fio_tls_destroy_context(tls); /* TODO: Library specific implementation */ /* Certificates */ FIO_ARY_FOR(&tls->sni, pos) { fio_str_info_s k = fio_str_info(&pos->private_key); fio_str_info_s p = fio_str_info(&pos->public_key); fio_str_info_s pw = f...
/** Called when the library specific data for the context should be built */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L234-L270
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_read
static ssize_t fio_tls_read(intptr_t uuid, void *udata, void *buf, size_t count) { ssize_t ret = read(fio_uuid2fd(uuid), buf, count); if (ret > 0) { FIO_LOG_DEBUG("Read %zd bytes from %p", ret, (void *)uuid); } return ret; (void)udata; }
/** * Implement reading from a file descriptor. Should behave like the file * system `read` call, including the setup or errno to EAGAIN / EWOULDBLOCK. * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or a * deadlock might occur. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L293-L301
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_flush
static ssize_t fio_tls_flush(intptr_t uuid, void *udata) { buffer_s *buffer = udata; if (!buffer->len) { FIO_LOG_DEBUG("Flush empty for %p", (void *)uuid); return 0; } ssize_t r = write(fio_uuid2fd(uuid), buffer->buffer, buffer->len); if (r < 0) return -1; if (r == 0) { errno = ECONNRESET; ...
/** * When implemented, this function will be called to flush any data remaining * in the internal buffer. * * The function should return the number of bytes remaining in the internal * buffer (0 is a valid response) or -1 (on error). * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L313-L332
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_write
static ssize_t fio_tls_write(intptr_t uuid, void *udata, const void *buf, size_t count) { buffer_s *buffer = udata; size_t can_copy = TLS_BUFFER_LENGTH - buffer->len; if (can_copy > count) can_copy = count; if (!can_copy) goto would_block; memcpy(buffer->buffer + buffer->l...
/** * Implement writing to a file descriptor. Should behave like the file system * `write` call. * * If an internal buffer is implemented and it is full, errno should be set to * EWOULDBLOCK and the function should return -1. * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or a * dead...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L344-L360
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_before_close
static ssize_t fio_tls_before_close(intptr_t uuid, void *udata) { FIO_LOG_DEBUG("The `before_close` callback was called for %p", (void *)uuid); return 1; (void)udata; }
/** * The `close` callback should close the underlying socket / file descriptor. * * If the function returns a non-zero value, it will be called again after an * attempt to flush the socket and any pending outgoing buffer. * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or a * deadlock...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L371-L375
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_cleanup
static void fio_tls_cleanup(void *udata) { buffer_s *buffer = udata; /* make sure the ALPN callback was called, just in case cleanup is required */ if (!buffer->alpn_ok) { alpn_select(alpn_default(buffer->tls), -1, NULL /* ALPN udata */); } fio_tls_destroy(buffer->tls); /* manage reference count */ fio_...
/** * Called to perform cleanup after the socket was closed. * */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L379-L387
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_cert_add
int FIO_TLS_WEAK fio_tls_cert_add(fio_tls_s *tls, const char *server_name, const char *cert, const char *key, const char *pk_password) { REQUIRE_LIBRARY(); cert_s c = { .private_key = FIO_STR_INIT, .public_key = FIO_STR_INIT, .p...
/** * Adds a certificate a new SSL/TLS context / settings object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L494-L522
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_alpn_add
void FIO_TLS_WEAK fio_tls_alpn_add( fio_tls_s *tls, const char *protocol_name, void (*on_selected)(intptr_t uuid, void *udata_connection, void *udata_tls), void *udata_tls, void (*on_cleanup)(void *udata_tls)) { REQUIRE_LIBRARY(); alpn_add(tls, protocol_name, on_selected, udata_tls, on_cleanup); fio_t...
/** * Adds an ALPN protocol callback to the SSL/TLS context. * * The first protocol added will act as the default protocol to be selected. * * The callback should accept the `uuid`, the user data pointer passed to either * `fio_tls_accept` or `fio_tls_connect` (here: `udata_connetcion`) and the user * data point...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L540-L547
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_alpn_count
uintptr_t FIO_TLS_WEAK fio_tls_alpn_count(fio_tls_s *tls) { return tls ? alpn_list_count(&tls->alpn) : 0; }
/** * Returns the number of registered ALPN protocol names. * * This could be used when deciding if protocol selection should be delegated to * the ALPN mechanism, or whether a protocol should be immediately assigned. * * If no ALPN protocols are registered, zero (0) is returned. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L557-L559
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_trust
int FIO_TLS_WEAK fio_tls_trust(fio_tls_s *tls, const char *public_cert_file) { REQUIRE_LIBRARY(); trust_s c = { .pem = FIO_STR_INIT, }; if (!public_cert_file) return 0; if (fio_str_readfile(&c.pem, public_cert_file, 0, 0).data == NULL) goto file_missing; trust_ary_push(&tls->trust, c); fio_t...
/** * Adds a certificate to the "trust" list, which automatically adds a peer * verification requirement. * * fio_tls_trust(tls, "google-ca.pem" ); */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L567-L583
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_accept
void FIO_TLS_WEAK fio_tls_accept(intptr_t uuid, fio_tls_s *tls, void *udata) { REQUIRE_LIBRARY(); fio_tls_attach2uuid(uuid, tls, udata, 1); }
/** * Establishes an SSL/TLS connection as an SSL/TLS Server, using the specified * context / settings object. * * The `uuid` should be a socket UUID that is already connected to a peer (i.e., * the result of `fio_accept`). * * The `udata` is an opaque user data pointer that is passed along to the * protocol se...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L595-L598
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_connect
void FIO_TLS_WEAK fio_tls_connect(intptr_t uuid, fio_tls_s *tls, void *udata) { REQUIRE_LIBRARY(); fio_tls_attach2uuid(uuid, tls, udata, 0); }
/** * Establishes an SSL/TLS connection as an SSL/TLS Client, using the specified * context / settings object. * * The `uuid` should be a socket UUID that is already connected to a peer (i.e., * one received by a `fio_connect` specified callback `on_connect`). * * The `udata` is an opaque user data pointer that ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L610-L613
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_dup
void FIO_TLS_WEAK fio_tls_dup(fio_tls_s *tls) { fio_atomic_add(&tls->ref, 1); }
/** * Increase the reference count for the TLS object. * * Decrease with `fio_tls_destroy`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L620-L620
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_destroy
void FIO_TLS_WEAK fio_tls_destroy(fio_tls_s *tls) { if (!tls) return; REQUIRE_LIBRARY(); if (fio_atomic_sub(&tls->ref, 1)) return; fio_tls_destroy_context(tls); alpn_list_free(&tls->alpn); cert_ary_free(&tls->sni); trust_ary_free(&tls->trust); free(tls); }
/** * Destroys the SSL/TLS context / settings object and frees any related * resources / memory. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_missing.c#L626-L637
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
alpn_add
FIO_FUNC inline void alpn_add( fio_tls_s *tls, const char *protocol_name, void (*on_selected)(intptr_t uuid, void *udata_connection, void *udata_tls), void *udata_tls, void (*on_cleanup)(void *udata_tls)) { alpn_s tmp = { .name = FIO_STR_INIT_STATIC(protocol_name), .on_selected = on_selected, ...
/** Adds an ALPN data object to the ALPN "list" (set) */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L159-L176
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
alpn_select
FIO_FUNC inline void alpn_select(alpn_s *alpn, intptr_t uuid, void *udata_connection) { if (!alpn || !alpn->on_selected) return; alpn_task_s *t = fio_malloc(sizeof(*t)); *t = (alpn_task_s){ .alpn = *alpn, .uuid = uuid, .udata_connection = udata_connection, ...
/** Schedules the ALPN protocol callback. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L200-L211
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_destroy_context
static void fio_tls_destroy_context(fio_tls_s *tls) { /* TODO: Library specific implementation */ SSL_CTX_free(tls->ctx); free(tls->alpn_str); tls->ctx = NULL; tls->alpn_str = NULL; tls->alpn_len = 0; FIO_LOG_DEBUG("destroyed TLS context for OpenSSL %p", (void *)tls); }
/** Called when the library specific data for the context should be destroyed */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L357-L366
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_build_context
static void fio_tls_build_context(fio_tls_s *tls) { fio_tls_destroy_context(tls); /* TODO: Library specific implementation */ /* create new context */ tls->ctx = SSL_CTX_new(TLS_method()); SSL_CTX_set_mode(tls->ctx, SSL_MODE_ENABLE_PARTIAL_WRITE); /* see: https://caniuse.com/#search=tls */ SSL_CTX_set_mi...
/** Called when the library specific data for the context should be built */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L381-L509
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_delayed_close
static void fio_tls_delayed_close(void *uuid, void *ignr_) { fio_close((intptr_t)uuid); (void)ignr_; }
/* ***************************************************************************** SSL/TLS RW Hooks ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L515-L518
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_read
static ssize_t fio_tls_read(intptr_t uuid, void *udata, void *buf, size_t count) { fio_tls_connection_s *c = udata; ssize_t ret = SSL_read(c->ssl, buf, count); if (ret > 0) return ret; ret = SSL_get_error(c->ssl, ret); switch (ret) { case SSL_ERROR_SSL: /* overflow */ case ...
/* TODO: this is an example implementation - fix for specific library. */ /** * Implement reading from a file descriptor. Should behave like the file * system `read` call, including the setup or errno to EAGAIN / EWOULDBLOCK. * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or a * deadloc...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L529-L555
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_flush
static ssize_t fio_tls_flush(intptr_t uuid, void *udata) { (void)uuid; (void)udata; return 0; }
/** * When implemented, this function will be called to flush any data remaining * in the internal buffer. * * The function should return the number of bytes remaining in the internal * buffer (0 is a valid response) or -1 (on error). * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L567-L571
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_write
static ssize_t fio_tls_write(intptr_t uuid, void *udata, const void *buf, size_t count) { fio_tls_connection_s *c = udata; ssize_t ret = SSL_write(c->ssl, buf, count); if (ret > 0) return ret; ret = SSL_get_error(c->ssl, ret); switch (ret) { case SSL_ERROR_SSL: /* overflow *...
/** * Implement writing to a file descriptor. Should behave like the file system * `write` call. * * If an internal buffer is implemented and it is full, errno should be set to * EWOULDBLOCK and the function should return -1. * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or a * dead...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L583-L609
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_before_close
static ssize_t fio_tls_before_close(intptr_t uuid, void *udata) { fio_tls_connection_s *c = udata; SSL_shutdown(c->ssl); return 1; (void)uuid; }
/** * The `close` callback should close the underlying socket / file descriptor. * * If the function returns a non-zero value, it will be called again after an * attempt to flush the socket and any pending outgoing buffer. * * Note: facil.io library functions MUST NEVER be called by any r/w hook, or a * deadlock...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L620-L625
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_cleanup
static void fio_tls_cleanup(void *udata) { fio_tls_connection_s *c = udata; if (!c->alpn_ok) { alpn_select(alpn_default(c->tls), -1, c->alpn_arg); } SSL_free(c->ssl); FIO_LOG_DEBUG("TLS cleanup for %p", (void *)c->uuid); fio_tls_destroy(c->tls); /* manage reference count */ free(udata); }
/** * Called to perform cleanup after the socket was closed. * */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L629-L638
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_cert_add
int FIO_TLS_WEAK fio_tls_cert_add(fio_tls_s *tls, const char *server_name, const char *cert, const char *key, const char *pk_password) { REQUIRE_LIBRARY(); cert_s c = { .private_key = FIO_STR_INIT, .public_key = FIO_STR_INIT, .p...
/** * Adds a certificate a new SSL/TLS context / settings object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L869-L897
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_alpn_add
void FIO_TLS_WEAK fio_tls_alpn_add( fio_tls_s *tls, const char *protocol_name, void (*on_selected)(intptr_t uuid, void *udata_connection, void *udata_tls), void *udata_tls, void (*on_cleanup)(void *udata_tls)) { REQUIRE_LIBRARY(); alpn_add(tls, protocol_name, on_selected, udata_tls, on_cleanup); fio_t...
/** * Adds an ALPN protocol callback to the SSL/TLS context. * * The first protocol added will act as the default protocol to be selected. * * The callback should accept the `uuid`, the user data pointer passed to * either `fio_tls_accept` or `fio_tls_connect` (here: `udata_connetcion`) and * the user data point...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L916-L923
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_alpn_count
uintptr_t FIO_TLS_WEAK fio_tls_alpn_count(fio_tls_s *tls) { return tls ? alpn_list_count(&tls->alpn) : 0; }
/** * Returns the number of registered ALPN protocol names. * * This could be used when deciding if protocol selection should be delegated * to the ALPN mechanism, or whether a protocol should be immediately * assigned. * * If no ALPN protocols are registered, zero (0) is returned. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L934-L936
675c65b509d48c21a8d1fa4c5ec53fc407643a3b