![]() |
kinetic-c
v0.12.0
Seagate Kinetic Protocol Client Library for C
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <assert.h>
#include <limits.h>
#include <sys/resource.h>
#include "bus.h"
#include "bus_poll.h"
#include "send.h"
#include "listener.h"
#include "threadpool.h"
#include "bus_internal_types.h"
#include "bus_ssl.h"
#include "util.h"
#include "yacht.h"
#include "syscall.h"
#include "atomic.h"
#include "kinetic_types_internal.h"
#include "listener_task.h"
Go to the source code of this file.
Macros | |
#define | THREAD_SHUTDOWN_SECONDS 5 |
Functions | |
static int | listener_id_of_socket (struct bus *b, int fd) |
static void | noop_log_cb (log_event_t event, int log_level, const char *msg, void *udata) |
static void | noop_error_cb (bus_unpack_cb_res_t result, void *socket_udata) |
static bool | attempt_to_increase_resource_limits (struct bus *b) |
static void | set_defaults (bus_config *cfg) |
bool | Bus_Init (bus_config *config, struct bus_result *res) |
Initialize a bus, based on configuration in *config. More... | |
static boxed_msg * | box_msg (struct bus *b, bus_user_msg *msg) |
bool | Bus_SendRequest (struct bus *b, bus_user_msg *msg) |
Send a request. More... | |
struct listener * | Bus_GetListenerForSocket (struct bus *b, int fd) |
For a given file descriptor, get the listener ID to use. More... | |
const char * | Bus_LogEventStr (log_event_t event) |
Get the string key for a log event ID. More... | |
bool | Bus_RegisterSocket (struct bus *b, bus_socket_t type, int fd, void *udata) |
Register a socket connected to an endpoint, and data that will be passed to all interactions on that socket. More... | |
bool | Bus_ReleaseSocket (struct bus *b, int fd, void **socket_udata_out) |
Free metadata about a socket that has been disconnected. More... | |
static void | free_connection_cb (void *value, void *udata) |
bool | Bus_Shutdown (bus *b) |
Begin shutting the system down. More... | |
void | Bus_BackpressureDelay (struct bus *b, size_t backpressure, uint8_t shift) |
Provide backpressure by sleeping for (backpressure >> shift) msec, if the value is greater than 0. More... | |
static void | box_execute_cb (void *udata) |
static void | box_cleanup_cb (void *udata) |
bool | Bus_ProcessBoxedMessage (struct bus *b, struct boxed_msg *box, size_t *backpressure) |
Deliver a boxed message to the thread pool to execute. More... | |
void | Bus_Free (bus *b) |
Free internal data structures for the bus. More... | |
|
static |
Definition at line 325 of file bus.c.
References bus::listener_count.
|
static |
|
static |
|
static |
Definition at line 195 of file bus.c.
References BUS_LOG_SNPRINTF, LOG_MEMORY, and bus::udata.
|
static |
Definition at line 51 of file bus.c.
References bus_config::listener_count.
bool Bus_Init | ( | bus_config * | config, |
struct bus_result * | res | ||
) |
Initialize a bus, based on configuration in *config.
Returns a bool indicating whether the construction succeeded, and the bus pointer and/or a status code indicating the cause of failure in *res.
Definition at line 64 of file bus.c.
References attempt_to_increase_resource_limits(), bus_result::bus, BUS_INIT_ERROR_ALLOC_FAIL, BUS_INIT_ERROR_LISTENER_INIT_FAIL, BUS_INIT_ERROR_MISSING_SINK_CB, BUS_INIT_ERROR_MISSING_UNPACK_CB, BUS_INIT_ERROR_MUTEX_INIT_FAIL, BUS_INIT_ERROR_NULL, BUS_INIT_ERROR_PTHREAD_INIT_FAIL, BUS_INIT_ERROR_THREADPOOL_INIT_FAIL, BUS_LOG, BUS_LOG_SNPRINTF, bus_config::bus_udata, BusSSL_Init(), DEF_FD_SET_SIZE2, bus::error_cb, bus_config::error_cb, bus::fd_set, bus::fd_set_lock, bus::joined, bus::listener_count, bus_config::listener_count, Listener_Free(), Listener_Init(), bus::listeners, ListenerTask_MainLoop(), bus::log_cb, bus_config::log_cb, LOG_INITIALIZATION, bus::log_level, bus_config::log_level, noop_error_cb(), noop_log_cb(), set_defaults(), bus::sink_cb, bus_config::sink_cb, bus_result::status, bus::threadpool, bus_config::threadpool_cfg, Threadpool_Free(), Threadpool_Init(), threadpool::threads, bus::threads, bus::udata, bus::unexpected_msg_cb, bus_config::unexpected_msg_cb, bus::unpack_cb, bus_config::unpack_cb, Yacht_Free(), and Yacht_Init().
|
static |
Definition at line 233 of file bus.c.
References BUS_DEFAULT_TIMEOUT_SEC, BUS_LOG_SNPRINTF, BUS_NO_SEQ_ID, boxed_msg::cb, bus_user_msg::cb, boxed_msg::fd, bus_user_msg::fd, bus::fd_set, bus::fd_set_lock, connection_info::largest_wr_seq_id_seen, LOG_MEMORY, bus_user_msg::msg, bus_user_msg::msg_size, boxed_msg::out_msg, boxed_msg::out_msg_size, boxed_msg::out_seq_id, bus_user_msg::seq_id, boxed_msg::ssl, connection_info::ssl, boxed_msg::timeout_sec, bus_user_msg::timeout_sec, boxed_msg::udata, bus::udata, bus_user_msg::udata, and Yacht_Get().
bool Bus_SendRequest | ( | struct bus * | b, |
bus_user_msg * | msg | ||
) |
Send a request.
Blocks until the request has been transmitted.
Assumes the FD has been registered with Bus_register_socket; sending to an unregistered socket is an error.
Returns true if the request has been accepted and the bus will attempt to handle the request and response. They can still fail, but the error status will be passed to the result handler callback.
Returns false if the request has been rejected, due to a memory allocation error or invalid arguments.
Definition at line 297 of file bus.c.
References box_msg(), BUS_LOG_SNPRINTF, bus_user_msg::fd, LOG_SENDING_REQUEST, Send_DoBlockingSend(), bus_user_msg::seq_id, and bus::udata.
For a given file descriptor, get the listener ID to use.
This will level sockets between multiple threads.
Definition at line 330 of file bus.c.
References listener_id_of_socket(), and bus::listeners.
const char* Bus_LogEventStr | ( | log_event_t | event | ) |
Get the string key for a log event ID.
Definition at line 335 of file bus.c.
References LOG_INITIALIZATION, LOG_LISTENER, LOG_MEMORY, LOG_NEW_CLIENT, LOG_SENDER, LOG_SENDING_REQUEST, LOG_SHUTDOWN, and LOG_SOCKET_REGISTERED.
bool Bus_RegisterSocket | ( | struct bus * | b, |
bus_socket_t | type, | ||
int | fd, | ||
void * | socket_udata | ||
) |
Register a socket connected to an endpoint, and data that will be passed to all interactions on that socket.
The socket will have request -> response messages with timeouts, as well as unsolicited status messages.
If USES_SSL is true, then the function will block until the initial SSL/TLS connection handshake has completed.
Definition at line 350 of file bus.c.
References BUS_LOG, BUS_LOG_SNPRINTF, BUS_NO_SEQ_ID, BUS_NO_SSL, BUS_SOCKET_SSL, BusPoll_OnCompletion(), BusSSL_Connect(), connection_info::fd, bus::fd_set, bus::fd_set_lock, connection_info::largest_wr_seq_id_seen, Listener_AddSocket(), listener_id_of_socket(), bus::listeners, LOG_SOCKET_REGISTERED, connection_info::ssl, connection_info::type, bus::udata, connection_info::udata, and Yacht_Set().
bool Bus_ReleaseSocket | ( | struct bus * | b, |
int | fd, | ||
void ** | socket_udata_out | ||
) |
Free metadata about a socket that has been disconnected.
Definition at line 420 of file bus.c.
References BUS_LOG_SNPRINTF, BUS_NO_SSL, BusPoll_OnCompletion(), BusSSL_Disconnect(), bus::fd_set, bus::fd_set_lock, listener_id_of_socket(), Listener_RemoveSocket(), bus::listeners, LOG_SOCKET_REGISTERED, connection_info::ssl, bus::udata, connection_info::udata, and Yacht_Remove().
|
static |
Definition at line 472 of file bus.c.
References BusPoll_OnCompletion(), connection_info::fd, listener_id_of_socket(), Listener_RemoveSocket(), and bus::listeners.
bool Bus_Shutdown | ( | struct bus * | b | ) |
Begin shutting the system down.
Returns true once everything pending has resolved.
Definition at line 494 of file bus.c.
References ATOMIC_BOOL_COMPARE_AND_SWAP, BUS_LOG, BUS_LOG_SNPRINTF, BusPoll_OnCompletion(), bus::fd_set, free_connection_cb(), bus::joined, bus::listener_count, Listener_Shutdown(), bus::listeners, LOG_SHUTDOWN, bus::shutdown_state, SHUTDOWN_STATE_HALTED, SHUTDOWN_STATE_RUNNING, SHUTDOWN_STATE_SHUTTING_DOWN, syscall_pthread_join(), bus::threads, bus::udata, and Yacht_Free().
void Bus_BackpressureDelay | ( | struct bus * | b, |
size_t | backpressure, | ||
uint8_t | shift | ||
) |
Provide backpressure by sleeping for (backpressure >> shift) msec, if the value is greater than 0.
Definition at line 551 of file bus.c.
References BUS_LOG_SNPRINTF, LOG_SENDER, syscall_poll(), and bus::udata.
|
static |
Definition at line 562 of file bus.c.
References boxed_msg::cb, boxed_msg::result, and boxed_msg::udata.
Deliver a boxed message to the thread pool to execute.
Definition at line 580 of file bus.c.
References box_cleanup_cb(), box_execute_cb(), BUS_LOG_SNPRINTF, BUS_SEND_UNDEFINED, LOG_MEMORY, boxed_msg::result, bus_msg_result_t::status, threadpool_task::task, bus::threadpool, Threadpool_Schedule(), and bus::udata.
void Bus_Free | ( | struct bus * | b | ) |
Free internal data structures for the bus.
Definition at line 599 of file bus.c.
References BUS_LOG, BUS_LOG_SNPRINTF, Bus_Shutdown(), BusSSL_CtxFree(), bus::fd_set_lock, bus::joined, limit, bus::listener_count, Listener_Free(), bus::listeners, LOG_SHUTDOWN, bus::shutdown_state, SHUTDOWN_STATE_HALTED, syscall_poll(), THREAD_SHUTDOWN_SECONDS, bus::threadpool, Threadpool_Free(), Threadpool_Shutdown(), bus::threads, and bus::udata.