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 | fio_flush_all | size_t fio_flush_all(void) {
if (!fio_data)
return 0;
size_t count = 0;
for (uintptr_t i = 0; i <= fio_data->max_protocol_fd; ++i) {
if ((fd_data(i).open || fd_data(i).packet) && fio_flush(fd2uuid(i)) > 0)
++count;
}
return count;
} | /** `fio_flush_all` attempts flush all the open connections. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3054-L3063 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_hooks_default_read | static ssize_t fio_hooks_default_read(intptr_t uuid, void *udata, void *buf,
size_t count) {
return read(fio_uuid2fd(uuid), buf, count);
(void)(udata);
} | /* *****************************************************************************
Connection Read / Write Hooks, for overriding the system calls
***************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3069-L3073 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_rw_hook_replace_unsafe | int fio_rw_hook_replace_unsafe(intptr_t uuid, fio_rw_hook_s *rw_hooks,
void *udata) {
int replaced = -1;
uint8_t was_locked;
intptr_t fd = fio_uuid2fd(uuid);
if (!rw_hooks->read)
rw_hooks->read = fio_hooks_default_read;
if (!rw_hooks->write)
rw_hooks->write = fio_hooks_d... | /**
* Replaces an existing read/write hook with another from within a read/write
* hook callback.
*
* Does NOT call any cleanup callbacks.
*
* Returns -1 on error, 0 on success.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3110-L3135 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_rw_hook_set | int fio_rw_hook_set(intptr_t uuid, fio_rw_hook_s *rw_hooks, void *udata) {
if (fio_is_closed(uuid))
goto invalid_uuid;
if (!rw_hooks->read)
rw_hooks->read = fio_hooks_default_read;
if (!rw_hooks->write)
rw_hooks->write = fio_hooks_default_write;
if (!rw_hooks->flush)
rw_hooks->flush = fio_hooks_... | /** Sets a socket hook state (a pointer to the struct). */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3138-L3171 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_attach__internal | static int fio_attach__internal(void *uuid_, void *protocol_) {
intptr_t uuid = (intptr_t)uuid_;
fio_protocol_s *protocol = (fio_protocol_s *)protocol_;
if (protocol) {
if (!protocol->on_close) {
protocol->on_close = mock_on_ev;
}
if (!protocol->on_data) {
protocol->on_data = mock_on_data;... | /* *****************************************************************************
Section Start Marker
IO Protocols and Attachment
***************************************************************************** */
/* ******************************************************... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3208-L3266 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_attach | void fio_attach(intptr_t uuid, fio_protocol_s *protocol) {
fio_attach__internal((void *)uuid, protocol);
} | /**
* Attaches (or updates) a protocol object to a socket UUID.
* Returns -1 on error and 0 on success.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3272-L3274 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_attach_fd | void fio_attach_fd(int fd, fio_protocol_s *protocol) {
fio_attach__internal((void *)fio_fd2uuid(fd), protocol);
} | /** Attaches (or updates) a protocol object to a socket UUID.
* Returns -1 on error and 0 on success.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3278-L3280 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_timeout_set | void fio_timeout_set(intptr_t uuid, uint8_t timeout) {
if (uuid_is_valid(uuid)) {
touchfd(fio_uuid2fd(uuid));
uuid_data(uuid).timeout = timeout;
} else {
FIO_LOG_DEBUG("Called fio_timeout_set for invalid uuid %p", (void *)uuid);
}
} | /** Sets a timeout for a specific connection (only when running and valid). */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3283-L3290 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_timeout_get | uint8_t fio_timeout_get(intptr_t uuid) { return uuid_data(uuid).timeout; } | /** Gets a timeout for a specific connection. Returns 0 if there's no set
* timeout or the connection is inactive. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3293-L3293 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_state_callback_add | void fio_state_callback_add(callback_type_e c_type, void (*func)(void *),
void *arg) {
if (c_type == FIO_CALL_ON_INITIALIZE && fio_data) {
func(arg);
return;
}
if (!func || (int)c_type < 0 || c_type > FIO_CALL_NEVER)
return;
fio_lock(&callback_collection[c_type].lock);
... | /** Adds a callback to the list of callbacks to be called for the event. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3323-L3338 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_state_callback_remove | int fio_state_callback_remove(callback_type_e c_type, void (*func)(void *),
void *arg) {
if ((int)c_type < 0 || c_type > FIO_CALL_NEVER)
return -1;
fio_lock(&callback_collection[c_type].lock);
FIO_LS_EMBD_FOR(&callback_collection[c_type].callbacks, pos) {
callback_data_s *tmp... | /** Removes a callback from the list of callbacks to be called for the event. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3341-L3359 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_state_callback_force | void fio_state_callback_force(callback_type_e c_type) {
if ((int)c_type < 0 || c_type > FIO_CALL_NEVER)
return;
/* copy collection */
fio_ls_embd_s copy = FIO_LS_INIT(copy);
fio_lock(&callback_collection[c_type].lock);
fio_state_callback_ensure(&callback_collection[c_type]);
switch (c_type) { ... | /** Forces all the existing callbacks to run, as if the event occurred. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3362-L3419 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_state_callback_clear | void fio_state_callback_clear(callback_type_e c_type) {
if ((int)c_type < 0 || c_type > FIO_CALL_NEVER)
return;
fio_lock(&callback_collection[c_type].lock);
fio_state_callback_ensure(&callback_collection[c_type]);
while (fio_ls_embd_any(&callback_collection[c_type].callbacks)) {
callback_data_s *tmp = F... | /** Clears all the existing callbacks for the event. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3422-L3434 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_io_task_perform | static void fio_io_task_perform(void *uuid_, void *args_) {
fio_defer_iotask_args_s *args = args_;
intptr_t uuid = (intptr_t)uuid_;
fio_protocol_s *pr = fio_protocol_try_lock(uuid, args->type);
if (!pr)
goto postpone;
args->task(uuid, pr, args->udata);
fio_protocol_unlock(pr, args->type);
fio_free(arg... | /* *****************************************************************************
IO bound tasks
***************************************************************************** */
// typedef struct {
// enum fio_protocol_lock_e type;
// void (*task)(intptr_t uuid, fio_protocol_s *, void *udata);
// void *udata;
// ... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3458-L3476 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | FIO_IGNORE_MACRO | void fio_defer_io_task FIO_IGNORE_MACRO(intptr_t uuid,
fio_defer_iotask_args_s args) {
if (!args.task) {
if (args.fallback)
fio_defer_push_task((void (*)(void *, void *))args.fallback, (void *)uuid,
args.udata);
return;
}
fio_defer_io... | /**
* Schedules a protected connection task. The task will run within the
* connection's lock.
*
* If an error ocuurs or the connection is closed before the task can run, the
* `fallback` task wil be called instead, allowing for resource cleanup.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3484-L3496 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_on_fork | static void fio_on_fork(void) {
fio_timer_lock = FIO_LOCK_INIT;
fio_data->lock = FIO_LOCK_INIT;
fio_defer_on_fork();
fio_malloc_after_fork();
fio_poll_init();
fio_state_callback_on_fork();
const size_t limit = fio_data->capa;
for (size_t i = 0; i < limit; ++i) {
fd_data(i).sock_lock = FIO_LOCK_INIT... | /* Called within a child process after it starts. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3505-L3530 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cycle_schedule_events | static void fio_cycle_schedule_events(void) {
static int idle = 0;
static time_t last_to_review = 0;
fio_mark_time();
fio_timer_schedule();
fio_max_fd_shrink();
if (fio_signal_children_flag) {
/* hot restart support */
fio_signal_children_flag = 0;
fio_cluster_signal_children();
}
int events... | /* reactor pattern cycling - common actions */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3712-L3741 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cycle_unwind | static void fio_cycle_unwind(void *ignr, void *ignr2) {
if (fio_data->connection_count) {
fio_cycle_schedule_events();
fio_defer_push_task(fio_cycle_unwind, ignr, ignr2);
return;
}
fio_stop();
return;
} | /* reactor pattern cycling during cleanup */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3744-L3752 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cycle | static void fio_cycle(void *ignr, void *ignr2) {
fio_cycle_schedule_events();
if (fio_data->active) {
fio_defer_push_task(fio_cycle, ignr, ignr2);
return;
}
return;
} | /* reactor pattern cycling */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3755-L3762 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_worker_startup | static void fio_worker_startup(void) {
/* Call the on_start callbacks for worker processes. */
if (fio_data->workers == 1 || fio_data->is_worker) {
fio_state_callback_force(FIO_CALL_ON_START);
fio_state_callback_clear(FIO_CALL_ON_START);
}
if (fio_data->workers == 1) {
/* Single Process - the root ... | /* TODO: fixme */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3765-L3795 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_worker_cleanup | static void fio_worker_cleanup(void) {
/* switch to winding down */
if (fio_data->is_worker)
FIO_LOG_INFO("(%d) detected exit signal.", (int)getpid());
else
FIO_LOG_INFO("Server Detected exit signal.");
fio_state_callback_force(FIO_CALL_ON_SHUTDOWN);
for (size_t i = 0; i <= fio_data->max_protocol_fd; ... | /* performs all clean-up / shutdown requirements except for the exit sequence */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3798-L3834 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | FIO_IGNORE_MACRO | void fio_start FIO_IGNORE_MACRO(struct fio_start_args args) {
fio_expected_concurrency(&args.threads, &args.workers);
fio_signal_handler_setup();
fio_data->workers = (uint16_t)args.workers;
fio_data->threads = (uint16_t)args.threads;
fio_data->active = 1;
fio_data->is_worker = 0;
fio_state_callback_forc... | /* marker for SublimeText3 jump feature */
/**
* Starts the facil.io event loop. This function will return after facil.io is
* done (after shutdown).
*
* See the `struct fio_start_args` details for any possible named arguments.
*
* This method blocks the current thread until the server is stopped (when a
* SIGIN... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3916-L3944 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_skip_zero | FIO_FUNC inline size_t fio_atol_skip_zero(char **pstr) {
char *const start = *pstr;
while (**pstr == '0') {
++(*pstr);
}
return (size_t)(*pstr - *start);
} | /* *****************************************************************************
Section Start Marker
Converting Numbers to Strings (and back)
***************************************************************************** */
/* ***************************************... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3986-L3992 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_consume | FIO_FUNC inline uint64_t fio_atol_consume(char **pstr, uint8_t base) {
uint64_t result = 0;
const uint64_t limit = UINT64_MAX - (base * base);
while (**pstr >= '0' && **pstr < ('0' + base) && result <= (limit)) {
result = (result * base) + (**pstr - '0');
++(*pstr);
}
return result;
} | /* consumes any digits in the string (base 2-10), returning their value */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L3995-L4003 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_skip_test | FIO_FUNC inline uint8_t fio_atol_skip_test(char **pstr, uint8_t base) {
return (**pstr >= '0' && **pstr < ('0' + base));
} | /* returns true if there's data to be skipped */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4006-L4008 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_skip | FIO_FUNC inline uint64_t fio_atol_skip(char **pstr, uint8_t base) {
uint64_t result = 0;
while (fio_atol_skip_test(pstr, base)) {
++result;
++(*pstr);
}
return result;
} | /* consumes any digits in the string (base 2-10), returning the count skipped */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4011-L4018 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_consume_hex | FIO_FUNC inline uint64_t fio_atol_consume_hex(char **pstr) {
uint64_t result = 0;
const uint64_t limit = UINT64_MAX - (16 * 16);
for (; result <= limit;) {
uint8_t tmp;
if (**pstr >= '0' && **pstr <= '9')
tmp = **pstr - '0';
else if (**pstr >= 'A' && **pstr <= 'F')
tmp = **pstr - ('A' - 10... | /* consumes any hex data in the string, returning their value */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4021-L4038 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_skip_hex_test | FIO_FUNC inline uint8_t fio_atol_skip_hex_test(char **pstr) {
return (**pstr >= '0' && **pstr <= '9') || (**pstr >= 'A' && **pstr <= 'F') ||
(**pstr >= 'a' && **pstr <= 'f');
} | /* returns true if there's data to be skipped */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4041-L4044 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol_skip_hex | FIO_FUNC inline uint64_t fio_atol_skip_hex(char **pstr) {
uint64_t result = 0;
while (fio_atol_skip_hex_test(pstr)) {
++result;
++(*pstr);
}
return result;
} | /* consumes any digits in the string (base 2-10), returning the count skipped */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4047-L4054 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atol | int64_t fio_atol(char **pstr) {
/* No binary representation in strtol */
char *str = *pstr;
uint64_t result = 0;
uint8_t invert = 0;
while (isspace(*str))
++(str);
if (str[0] == '-') {
invert ^= 1;
++str;
} else if (*str == '+') {
++(str);
}
if (str[0] == 'B' || str[0] == 'b' ||
... | /* caches a up to 8*8 */
// static inline fio_atol_pow_10_cache(size_t ex) {}
/**
* A helper function that converts between String data to a signed int64_t.
*
* Numbers are assumed to be in base 10. Octal (`0###`), Hex (`0x##`/`x##`) and
* binary (`0b##`/ `b##`) are recognized as well. For binary Most Significant
... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4069-L4126 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_atof | double fio_atof(char **pstr) { return strtold(*pstr, pstr); } | /** A helper function that converts between String data to a signed double. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4129-L4129 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_ltoa | size_t fio_ltoa(char *dest, int64_t num, uint8_t base) {
const char notation[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
size_t len = 0;
char buf[48]; /* we only need up to 20 for base 10, but base 3 needs 41... */
if (!num)
goto zero;
... | /* *****************************************************************************
Numbers to Strings
***************************************************************************** */
/**
* A helper function that writes a signed int64_t to a string.
*
* No overflow guard is provided, make sure there's at least 68 bytes... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4148-L4300 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_ftoa | size_t fio_ftoa(char *dest, double num, uint8_t base) {
if (base == 2 || base == 16) {
/* handle the binary / Hex representation the same as if it were an
* int64_t
*/
int64_t *i = (void *)#
return fio_ltoa(dest, *i, base);
}
size_t written = sprintf(dest, "%g", num);
uint8_t need_zer... | /**
* A helper function that converts between a double to a string.
*
* No overflow guard is provided, make sure there's at least 130 bytes
* available (for base 2).
*
* Supports base 2, base 10 and base 16. An unsupported base will silently
* default to base 10. Prefixes aren't added (i.e., no "0x" or "0b" at t... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4315-L4341 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_tls_alpn_count | uintptr_t FIO_TLS_WEAK fio_tls_alpn_count(void *tls) {
return 0;
(void)tls;
} | /* *****************************************************************************
Section Start Marker
SSL/TLS Weak Symbols for TLS Support
***************************************************************************** */
/**
* Returns the number of registered ALPN protocol names.
... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4371-L4374 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_tls_accept | void FIO_TLS_WEAK fio_tls_accept(intptr_t uuid, void *tls, void *udata) {
FIO_LOG_FATAL("No supported SSL/TLS library available.");
exit(-1);
return;
(void)uuid;
(void)tls;
(void)udata;
} | /**
* 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/fio.c#L4386-L4393 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_tls_connect | void FIO_TLS_WEAK fio_tls_connect(intptr_t uuid, void *tls, void *udata) {
FIO_LOG_FATAL("No supported SSL/TLS library available.");
exit(-1);
return;
(void)uuid;
(void)tls;
(void)udata;
} | /**
* 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/fio.c#L4405-L4412 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_tls_dup | void FIO_TLS_WEAK fio_tls_dup(void *tls) {
FIO_LOG_FATAL("No supported SSL/TLS library available.");
exit(-1);
return;
(void)tls;
} | /**
* Increase the reference count for the TLS object.
*
* Decrease with `fio_tls_destroy`.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4419-L4424 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_tls_destroy | void FIO_TLS_WEAK fio_tls_destroy(void *tls) {
FIO_LOG_FATAL("No supported SSL/TLS library available.");
exit(-1);
return;
(void)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/fio.c#L4430-L4435 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | FIO_IGNORE_MACRO | intptr_t fio_listen FIO_IGNORE_MACRO(struct fio_listen_args args) {
// ...
if ((!args.on_open && (!args.tls || !fio_tls_alpn_count(args.tls))) ||
(!args.address && !args.port)) {
errno = EINVAL;
goto error;
}
size_t addr_len = 0;
size_t port_len = 0;
if (args.address)
addr_len = strlen(ar... | /**
* Schedule a network service on a listening socket.
*
* Returns the listening socket or -1 (on error).
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4563-L4644 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_url_parse | fio_url_s fio_url_parse(const char *url, size_t length) {
/*
Intention:
[schema://][user[:]][password[@]][host.com[:/]][:port/][/path][?quary][#target]
*/
const char *end = url + length;
const char *pos = url;
fio_url_s r = {.scheme = {.data = (char *)url}};
if (length == 0) {
goto finish;
}
if... | /* *****************************************************************************
URL address parsing
***************************************************************************** */
/**
* Parses the URI returning it's components and their lengths (no decoding
* performed, doesn't accept decoded URIs).
*
* The retur... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L4811-L5027 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_channel_free | static void fio_channel_free(channel_s *ch) {
if (!ch)
return;
if (fio_atomic_sub(&ch->ref, 1))
return;
free(ch);
} | /** Frees a channel (reference counting). */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5158-L5164 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_channel_dup | static void fio_channel_dup(channel_s *ch) {
if (!ch)
return;
fio_atomic_add(&ch->ref, 1);
} | /** Increases a channel's reference count. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5166-L5170 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_channel_cmp | static int fio_channel_cmp(channel_s *ch1, channel_s *ch2) {
return ch1->name_len == ch2->name_len && ch1->match == ch2->match &&
!memcmp(ch1->name, ch2->name, ch1->name_len);
} | /** Tests if two channels are equal. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5172-L5175 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_postoffice_meta_copy_new | static fio_meta_ary_s fio_postoffice_meta_copy_new(void) {
fio_meta_ary_s t = FIO_ARY_INIT;
if (!fio_meta_ary_count(&fio_postoffice.meta.ary)) {
return t;
}
fio_lock(&fio_postoffice.meta.lock);
fio_meta_ary_concat(&t, &fio_postoffice.meta.ary);
fio_unlock(&fio_postoffice.meta.lock);
return t;
} | /* *****************************************************************************
Internal message object creation
***************************************************************************** */
/** returns a temporary fio_meta_ary_s with a copy of the metadata array */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5251-L5260 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_postoffice_meta_copy_free | static inline void fio_postoffice_meta_copy_free(fio_meta_ary_s *cpy) {
fio_meta_ary_free(cpy);
} | /** frees a temporary copy created by postoffice_meta_copy_new */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5263-L5265 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_msg_internal_finalize | static inline void fio_msg_internal_finalize(fio_msg_internal_s *m) {
if (!m->channel.len)
m->channel.data = NULL;
if (!m->data.len)
m->data.data = NULL;
} | /** frees the internal message data */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5321-L5326 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_msg_internal_free | static inline void fio_msg_internal_free(fio_msg_internal_s *m) {
if (fio_atomic_sub(&m->ref, 1))
return;
while (m->meta_len) {
--m->meta_len;
if (m->meta[m->meta_len].on_finish) {
fio_msg_s tmp_msg = {
.channel = m->channel,
.msg = m->data,
};
m->meta[m->meta_len].... | /** frees the internal message data */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5329-L5343 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_msg_internal_send_dup | static inline ssize_t fio_msg_internal_send_dup(intptr_t uuid,
fio_msg_internal_s *m) {
return fio_write2(uuid, .data.buffer = fio_msg_internal_dup(m),
.offset = (sizeof(*m) + (m->meta_len * sizeof(*m->meta))),
.length = 16 + m->d... | /** internal helper */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5355-L5361 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_mock_on_message | static void fio_mock_on_message(fio_msg_s *msg) { (void)msg; } | /**
* A mock pub/sub callback for external subscriptions.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5366-L5366 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_subscription_free | static inline void fio_subscription_free(subscription_s *s) {
if (fio_atomic_sub(&s->ref, 1)) {
return;
}
if (s->on_unsubscribe) {
s->on_unsubscribe(s->udata1, s->udata2);
}
fio_channel_free(s->parent);
fio_free(s);
} | /* to be used for reference counting (subtructing) */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5437-L5446 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_unsubscribe | void fio_unsubscribe(subscription_s *s) {
if (!s)
return;
if (fio_trylock(&s->unsubscribed))
goto finish;
fio_lock(&s->lock);
channel_s *ch = s->parent;
uint8_t removed = 0;
fio_lock(&ch->lock);
fio_ls_embd_remove(&s->node);
/* check if channel is done for */
if (fio_ls_embd_is_empty(&ch->subs... | /** Unsubscribes from a filter, pub/sub channle or patten */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5484-L5518 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_subscription_channel | fio_str_info_s fio_subscription_channel(subscription_s *subscription) {
return (fio_str_info_s){.data = subscription->parent->name,
.len = subscription->parent->name_len};
} | /**
* This helper returns a temporary String with the subscription's channel (or a
* string representing the filter).
*
* To keep the string beyond the lifetime of the subscription, copy the string.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5526-L5529 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_on_channel_create | static void fio_pubsub_on_channel_create(channel_s *ch) {
fio_lock(&fio_postoffice.engines.lock);
FIO_SET_FOR_LOOP(&fio_postoffice.engines.set, pos) {
if (!pos->hash)
continue;
pos->obj->subscribe(pos->obj,
(fio_str_info_s){.data = ch->name, .len = ch->name_len},
... | /* runs in lock(!) let'm all know */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5540-L5551 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_on_channel_destroy | static void fio_pubsub_on_channel_destroy(channel_s *ch) {
fio_lock(&fio_postoffice.engines.lock);
FIO_SET_FOR_LOOP(&fio_postoffice.engines.set, pos) {
if (!pos->hash)
continue;
pos->obj->unsubscribe(
pos->obj, (fio_str_info_s){.data = ch->name, .len = ch->name_len},
ch->match);
}
... | /* runs in lock(!) let'm all know */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5554-L5565 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_attach | void fio_pubsub_attach(fio_pubsub_engine_s *engine) {
fio_lock(&fio_postoffice.engines.lock);
fio_engine_set_insert(&fio_postoffice.engines.set, (uintptr_t)engine, engine);
fio_unlock(&fio_postoffice.engines.lock);
fio_pubsub_reattach(engine);
} | /**
* Attaches an engine, so it's callback can be called by facil.io.
*
* The `subscribe` callback will be called for every existing channel.
*
* NOTE: the root (master) process will call `subscribe` for any channel in any
* process, while all the other processes will call `subscribe` only for their
* own channe... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5577-L5582 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_detach | void fio_pubsub_detach(fio_pubsub_engine_s *engine) {
fio_lock(&fio_postoffice.engines.lock);
fio_engine_set_remove(&fio_postoffice.engines.set, (uintptr_t)engine, engine,
NULL);
fio_unlock(&fio_postoffice.engines.lock);
} | /** Detaches an engine, so it could be safely destroyed. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5585-L5590 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_is_attached | int fio_pubsub_is_attached(fio_pubsub_engine_s *engine) {
fio_pubsub_engine_s *addr;
fio_lock(&fio_postoffice.engines.lock);
addr = fio_engine_set_find(&fio_postoffice.engines.set, (uintptr_t)engine,
engine);
fio_unlock(&fio_postoffice.engines.lock);
return addr != NULL;
} | /** Returns true (1) if the engine is attached to the system. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5593-L5600 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_reattach | void fio_pubsub_reattach(fio_pubsub_engine_s *eng) {
fio_lock(&fio_postoffice.pubsub.lock);
FIO_SET_FOR_LOOP(&fio_postoffice.pubsub.channels, pos) {
if (!pos->hash)
continue;
eng->subscribe(
eng,
(fio_str_info_s){.data = pos->obj->name, .len = pos->obj->name_len},
NULL);
}
... | /**
* Engines can ask facil.io to call the `subscribe` callback for all active
* channels.
*
* This allows engines that lost their connection to their Pub/Sub service to
* resubscribe all the currently active channels with the new connection.
*
* CAUTION: This is an evented task... try not to free the engine's m... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5617-L5638 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_message_metadata_callback_set | void fio_message_metadata_callback_set(fio_msg_metadata_fn callback,
int enable) {
if (!callback)
return;
fio_lock(&fio_postoffice.meta.lock);
fio_meta_ary_remove2(&fio_postoffice.meta.ary, callback, NULL);
if (enable)
fio_meta_ary_push(&fio_postoffice.meta.ary, ca... | /* *****************************************************************************
* Message Metadata handling
**************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5644-L5653 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_message_defer | void fio_message_defer(fio_msg_s *msg_) {
fio_msg_client_s *cl = (fio_msg_client_s *)msg_;
cl->marker = 1;
} | /* defers the callback (mark only) */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5705-L5708 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_perform_subscription_callback | static void fio_perform_subscription_callback(void *s_, void *msg_) {
subscription_s *s = s_;
if (fio_trylock(&s->lock)) {
fio_defer_push_task(fio_perform_subscription_callback, s_, msg_);
return;
}
fio_msg_internal_s *msg = (fio_msg_internal_s *)msg_;
fio_msg_client_s m = {
.msg =
{
... | /* performs the actual callback */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5711-L5742 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_publish2channel | static void fio_publish2channel(channel_s *ch, fio_msg_internal_s *msg) {
FIO_LS_EMBD_FOR(&ch->subscriptions, pos) {
subscription_s *s = FIO_LS_EMBD_OBJ(subscription_s, node, pos);
if (!s || s->on_message == fio_mock_on_message) {
continue;
}
fio_atomic_add(&s->ref, 1);
fio_atomic_add(&msg->... | /** UNSAFE! publishes a message to a channel, managing the reference counts */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5745-L5756 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_publish2process | static void fio_publish2process(fio_msg_internal_s *m) {
fio_msg_internal_finalize(m);
channel_s *ch;
if (m->filter) {
ch = fio_filter_find_dup(m->filter);
if (!ch) {
goto finish;
}
} else {
ch = fio_channel_find_dup(m->channel);
}
/* exact match */
if (ch) {
fio_defer_push_urgen... | /** Publishes the message to the current process and frees the strings. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5774-L5810 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_protocol_free | static inline void fio_cluster_protocol_free(void *pr) { fio_free(pr); } | /* *****************************************************************************
* Cluster Protocol callbacks
**************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L5921-L5921 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_server_sender | static void fio_cluster_server_sender(void *m_, intptr_t avoid_uuid) {
fio_msg_internal_s *m = m_;
fio_lock(&cluster_data.lock);
FIO_LS_FOR(&cluster_data.clients, pos) {
if ((intptr_t)pos->obj != -1) {
if ((intptr_t)pos->obj != avoid_uuid) {
fio_msg_internal_send_dup((intptr_t)pos->obj, m);
... | /* *****************************************************************************
* Master (server) IPC Connections
**************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6086-L6098 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_listen_accept | static void fio_cluster_listen_accept(intptr_t uuid, fio_protocol_s *protocol) {
(void)protocol;
/* prevent `accept` backlog in parent */
intptr_t client;
while ((client = fio_accept(uuid)) != -1) {
fio_attach(client,
fio_cluster_protocol_alloc(client, fio_cluster_server_handler,
... | /** Called when a ne client is available */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6185-L6197 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_listen_on_close | static void fio_cluster_listen_on_close(intptr_t uuid,
fio_protocol_s *protocol) {
free(protocol);
cluster_data.uuid = -1;
if (fio_parent_pid() == getpid()) {
#if DEBUG
FIO_LOG_DEBUG("(%d) stopped listening for cluster connections",
(int)getpid());
#en... | /** Called when the connection was closed, but will not run concurrently */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6200-L6213 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_client_handler | static void fio_cluster_client_handler(struct cluster_pr_s *pr) {
/* what to do? */
switch ((fio_cluster_message_type_e)pr->type) {
case FIO_CLUSTER_MSG_FORWARD: /* fallthrough */
case FIO_CLUSTER_MSG_JSON:
fio_publish2process(fio_msg_internal_dup(pr->msg));
break;
case FIO_CLUSTER_MSG_SHUTDOWN:
f... | /* *****************************************************************************
* Worker (client) IPC connections
**************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6243-L6264 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_on_connect | static void fio_cluster_on_connect(intptr_t uuid, void *udata) {
cluster_data.uuid = uuid;
/* inform root about all existing channels */
fio_lock(&fio_postoffice.pubsub.lock);
FIO_SET_FOR_LOOP(&fio_postoffice.pubsub.channels, pos) {
if (!pos->hash) {
continue;
}
fio_cluster_inform_root_about_... | /** The address of the server we are connecting to. */
// char *address;
/** The port on the server we are connecting to. */
// char *port;
/**
* The `on_connect` callback should return a pointer to a protocol object
* that will handle any connection related events.
*
* Should either call `facil_attach` or close th... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6287-L6311 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_on_fail | static void fio_cluster_on_fail(intptr_t uuid, void *udata) {
FIO_LOG_FATAL("(facil.io) unknown cluster connection error");
perror(" errno");
kill(fio_parent_pid(), SIGINT);
fio_stop();
// exit(errno ? errno : 1);
(void)udata;
(void)uuid;
} | /**
* The `on_fail` is called when a socket fails to connect. The old sock UUID
* is passed along.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6316-L6324 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_inform_root_about_channel | static inline void fio_cluster_inform_root_about_channel(channel_s *ch,
int add) {
if (!fio_data->is_worker || fio_data->workers == 1 || !cluster_data.uuid ||
!ch)
return;
fio_str_info_s ch_name = {.data = ch->name, .len = ch->name_len};
fio_str_i... | /* *****************************************************************************
* Propegation
**************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6357-L6388 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_accept_after_fork | static void fio_accept_after_fork(void *ignore) {
/* prevent `accept` backlog in parent */
fio_cluster_listen_accept(cluster_data.uuid, NULL);
(void)ignore;
} | /* *****************************************************************************
* Initialization
**************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6394-L6398 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_on_fork | static void fio_pubsub_on_fork(void) {
fio_postoffice.filters.lock = FIO_LOCK_INIT;
fio_postoffice.pubsub.lock = FIO_LOCK_INIT;
fio_postoffice.patterns.lock = FIO_LOCK_INIT;
fio_postoffice.engines.lock = FIO_LOCK_INIT;
fio_postoffice.meta.lock = FIO_LOCK_INIT;
cluster_data.lock = FIO_LOCK_INIT;
cluster_da... | /* *****************************************************************************
Cluster forking handler
***************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6465-L6497 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_cluster_signal_children | static void fio_cluster_signal_children(void) {
if (fio_parent_pid() != getpid()) {
fio_stop();
return;
}
fio_cluster_server_sender(fio_msg_internal_create(0, FIO_CLUSTER_MSG_SHUTDOWN,
(fio_str_info_s){.len = 0},
... | /* *****************************************************************************
* External API
**************************************************************************** */
/** Signals children (or self) to shutdown) - NOT signal safe. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6504-L6514 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | FIO_IGNORE_MACRO | void fio_publish FIO_IGNORE_MACRO(fio_publish_args_s args) {
if (args.filter && !args.engine) {
args.engine = FIO_PUBSUB_CLUSTER;
} else if (!args.engine) {
args.engine = FIO_PUBSUB_DEFAULT;
}
fio_msg_internal_s *m = NULL;
switch ((uintptr_t)args.engine) {
case 0UL: /* fallthrough (missing default) ... | /**
* Publishes a message to the relevant subscribers (if any).
*
* See `facil_publish_args_s` for details.
*
* By default the message is sent using the FIO_PUBSUB_CLUSTER engine (all
* processes, including the calling process).
*
* To limit the message only to other processes (exclude the calling process),
* ... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6535-L6586 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_glob_match | static int fio_glob_match(fio_str_info_s pat, fio_str_info_s ch) {
/* adapted and rewritten, with thankfulness, from the code at:
* https://github.com/opnfv/kvmfornfv/blob/master/kernel/lib/glob.c
*
* Original version's copyright:
* Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
... | /* *****************************************************************************
* Glob Matching
**************************************************************************** */
/** A binary glob matching helper. Returns 1 on match, otherwise returns 0. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6593-L6684 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_pubsub_on_fork | static void fio_pubsub_on_fork(void) {} | /* FIO_PUBSUB_SUPPORT */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6690-L6690 | 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
***************************************************************************** */
/** used internally, only when memory addresses are known to be aligned */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L6811-L6882 | 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/fio.c#L6937-L6937 | 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/fio.c#L6971-L6973 | 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 = FIO_LOCK_INIT;
memory.forked = 1;
for (size_t i = 0; i < memory.cores; ++i) {
arenas[i].lock = FIO_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/fio.c#L7082-L7092 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | block_init_root | static inline void block_init_root(block_s *blk, block_s *parent) {
*blk = (block_s){
.parent = parent,
.ref = 1,
.pos = FIO_MEMORY_BLOCK_START_POS,
.root_ref = 1,
};
} | /* *****************************************************************************
Block management / allocation
***************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7098-L7105 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | block_init | static inline void block_init(block_s *blk) {
/* initialization shouldn't effect `parent` or `root_ref`*/
blk->ref = 1;
blk->pos = FIO_MEMORY_BLOCK_START_POS;
/* zero out linked list memory (everything else is already zero) */
((block_node_s *)blk)->node.next = NULL;
((block_node_s *)blk)->node.prev = NULL;... | /* intializes the block header for an available block of memory. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7108-L7117 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | block_free | static inline void block_free(block_s *blk) {
if (fio_atomic_sub(&blk->ref, 1))
return;
memset(blk + 1, 0, (FIO_MEMORY_BLOCK_SIZE - sizeof(*blk)));
fio_lock(&memory.lock);
fio_ls_embd_push(&memory.available, &((block_node_s *)blk)->node);
blk = blk->parent;
if (fio_atomic_sub(&blk->root_ref, 1)) {
... | /* intializes the block header for an available block of memory. */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7120-L7148 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | block_slice_free | static inline void block_slice_free(void *mem) {
/* locate block boundary */
block_s *blk = (block_s *)((uintptr_t)mem & (~FIO_MEMORY_BLOCK_MASK));
block_free(blk);
} | /* handle's a bock's reference count - called without a lock */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7216-L7220 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | big_free | static inline void big_free(void *ptr) {
size_t *mem = (void *)(((uintptr_t)ptr) - 16);
sys_free(mem, *mem);
} | /* reads size header and frees memory back to the system */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7239-L7242 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_rand64 | uint64_t fio_rand64(void) {
/* modeled after xoroshiro128+, by David Blackman and Sebastiano Vigna */
static __thread uint64_t s[2]; /* random state */
static __thread uint16_t c; /* seed counter */
const uint64_t P[] = {0x37701261ED6C16C7ULL, 0x764DBBB75F3B3E0DULL};
if (c++ == 0) {
/* re-seed state ev... | /* *****************************************************************************
Random Generator Functions
***************************************************************************** */
/* tested for randomness using code from: http://xoshiro.di.unimi.it/hwd.php */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7461-L7483 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_rand_bytes | void fio_rand_bytes(void *data_, size_t len) {
if (!data_ || !len)
return;
uint8_t *data = data_;
/* unroll 32 bytes / 256 bit writes */
for (size_t i = (len >> 5); i; --i) {
const uint64_t t0 = fio_rand64();
const uint64_t t1 = fio_rand64();
const uint64_t t2 = fio_rand64();
const uint64_t ... | /* copies 64 bits of randomness (8 bytes) repeatedly... */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7486-L7544 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_sha1_perform_all_rounds | static inline void fio_sha1_perform_all_rounds(fio_sha1_s *s,
const uint8_t *buffer) {
/* collect data */
uint32_t a = s->digest.i[0];
uint32_t b = s->digest.i[1];
uint32_t c = s->digest.i[2];
uint32_t d = s->digest.i[3];
uint32_t e = s->digest.i[4];
uint32_t... | /**
Process the buffer once full.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7693-L7813 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_sha1_init | fio_sha1_s fio_sha1_init(void) {
return (fio_sha1_s){.digest.i[0] = 0x67452301,
.digest.i[1] = 0xefcdab89,
.digest.i[2] = 0x98badcfe,
.digest.i[3] = 0x10325476,
.digest.i[4] = 0xc3d2e1f0};
} | /**
Initialize or reset the `sha1` object. This must be performed before hashing
data using sha1.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7819-L7825 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_sha1_write | void fio_sha1_write(fio_sha1_s *s, const void *data, size_t len) {
size_t in_buffer = s->length & 63;
size_t partial = 64 - in_buffer;
s->length += len;
if (partial > len) {
memcpy(s->buffer + in_buffer, data, len);
return;
}
if (in_buffer) {
memcpy(s->buffer + in_buffer, data, partial);
len... | /**
Writes data to the sha1 buffer.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7830-L7853 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_sha2_perform_all_rounds | static inline void fio_sha2_perform_all_rounds(fio_sha2_s *s,
const uint8_t *data) {
if (s->type & 1) { /* 512 derived type */
// process values for the 64bit words
uint64_t a = s->digest.i64[0];
uint64_t b = s->digest.i64[1];
uint64_t c = s->digest.i64[2... | /**
Process the buffer once full.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L7957-L8134 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_sha2_init | fio_sha2_s fio_sha2_init(fio_sha2_variant_e variant) {
if (variant == SHA_256) {
return (fio_sha2_s){
.type = SHA_256,
.digest.i32[0] = 0x6a09e667,
.digest.i32[1] = 0xbb67ae85,
.digest.i32[2] = 0x3c6ef372,
.digest.i32[3] = 0xa54ff53a,
.digest.i32[4] = 0x510e527f,
... | /**
Initialize/reset the SHA-2 object.
SHA-2 is actually a family of functions with different variants. When
initializing the SHA-2 container, you must select the variant you intend to
apply. The following are valid options (see the fio_sha2_variant_e enum):
- SHA_512 (== 0)
- SHA_384
- SHA_512_224
- SHA_512_256
- SH... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8151-L8227 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_sha2_write | void fio_sha2_write(fio_sha2_s *s, const void *data, size_t len) {
size_t in_buffer;
size_t partial;
if (s->type & 1) { /* 512 type derived */
in_buffer = s->length.words[0] & 127;
if (s->length.words[0] + len < s->length.words[0]) {
/* we are at wraping around the 64bit limit */
s->length.wor... | /**
Writes data to the SHA-2 buffer.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8232-L8290 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_base64_encode_internal | static inline int fio_base64_encode_internal(char *target, const char *data,
int len,
const char *base64_encodes) {
/* walk backwards, allowing fo inplace decoding (target == data) */
int groups = len / 3;
const int mod = le... | /*
* The actual encoding logic. The map can be switched for encoding variations.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8453-L8491 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_base64_encode | int fio_base64_encode(char *target, const char *data, int len) {
return fio_base64_encode_internal(target, data, len, base64_encodes_original);
} | /**
This will encode a byte array (data) of a specified length (len) and
place the encoded data into the target byte buffer (target). The target buffer
MUST have enough room for the expected data.
Base64 encoding always requires 4 bytes for each 3 bytes. Padding is added if
the raw data's length isn't devisable by 3.
... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8509-L8511 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_base64url_encode | int fio_base64url_encode(char *target, const char *data, int len) {
return fio_base64_encode_internal(target, data, len, base64_encodes_url);
} | /**
Same as fio_base64_encode, but using Base64URL encoding.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8516-L8518 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_base64_decode | int fio_base64_decode(char *target, char *encoded, int base64_len) {
if (!target)
target = encoded;
if (base64_len <= 0) {
target[0] = 0;
return 0;
}
int written = 0;
uint8_t tmp1, tmp2, tmp3, tmp4;
// skip unknown data at end
while (base64_len &&
!base64_decodes[*(uint8_t *)(encoded ... | /**
This will decode a Base64 encoded string of a specified length (len) and
place the decoded data into the target byte buffer (target).
The target buffer MUST have enough room for the expected data.
A NULL byte will be appended to the target buffer. The function will return
the number of bytes written to the target... | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8542-L8641 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_str_test | FIO_FUNC inline void fio_str_test(void) {
#define ROUND_UP_CAPA_2WORDS(num) \
(((num + 1) & (sizeof(long double) - 1)) \
? ((num + 1) | (sizeof(long double) - 1)) \
: (num))
fprintf(stderr, "... | /**
* Tests the fio_str functionality.
*/ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L8870-L9167 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
zap | github_2023 | zigzap | c | fio_state_callback_test_task | FIO_FUNC void fio_state_callback_test_task(void *pi) {
((uintptr_t *)pi)[0] += 1;
} | /* *****************************************************************************
Testing Core Callback add / remove / ensure
***************************************************************************** */ | https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fio.c#L9328-L9330 | 675c65b509d48c21a8d1fa4c5ec53fc407643a3b |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.