kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
Macros | Functions
bus.c File Reference
#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_msgbox_msg (struct bus *b, bus_user_msg *msg)
 
bool Bus_SendRequest (struct bus *b, bus_user_msg *msg)
 Send a request. More...
 
struct listenerBus_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...
 

Macro Definition Documentation

#define THREAD_SHUTDOWN_SECONDS   5

Definition at line 597 of file bus.c.

Function Documentation

static int listener_id_of_socket ( struct bus b,
int  fd 
)
static

Definition at line 325 of file bus.c.

References bus::listener_count.

static void noop_log_cb ( log_event_t  event,
int  log_level,
const char *  msg,
void *  udata 
)
static

Definition at line 636 of file bus.c.

static void noop_error_cb ( bus_unpack_cb_res_t  result,
void *  socket_udata 
)
static

Definition at line 644 of file bus.c.

static bool attempt_to_increase_resource_limits ( struct bus b)
static

Definition at line 195 of file bus.c.

References BUS_LOG_SNPRINTF, LOG_MEMORY, and bus::udata.

static void set_defaults ( bus_config cfg)
static

Definition at line 51 of file bus.c.

References bus_config::listener_count.

bool Bus_Init ( bus_config config,
struct bus_result res 
)
static boxed_msg* box_msg ( struct bus b,
bus_user_msg msg 
)
static
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.

struct listener* Bus_GetListenerForSocket ( struct bus b,
int  fd 
)

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 
)
static void free_connection_cb ( void *  value,
void *  udata 
)
static
bool Bus_Shutdown ( struct bus b)
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 void box_execute_cb ( void *  udata)
static

Definition at line 562 of file bus.c.

References boxed_msg::cb, boxed_msg::result, and boxed_msg::udata.

static void box_cleanup_cb ( void *  udata)
static

Definition at line 573 of file bus.c.

bool Bus_ProcessBoxedMessage ( struct bus b,
struct boxed_msg box,
size_t *  backpressure 
)
void Bus_Free ( struct bus b)