Ripples 1.0
High Performant Software Architecture For Transaction Processing
Loading...
Searching...
No Matches
conn.c File Reference
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/socket.h>
#include <unistd.h>
#include "config.h"
#include "conn.h"
#include "constants.h"
#include "lru_cache.h"
#include "query.h"
#include "utils.h"
Include dependency graph for conn.c:

Functions

static char * listener_err_to_str (int err)
 
void conn_tcp_release (conn_tcp_t *conn_tcp)
 
void conn_udp_release (conn_udp_t *conn_udp)
 
void conn_release (conn_t *conn)
 
conn_tconn_new_tcp (int fd, config_t *cfg, int ip_version, struct sockaddr_storage *client_ip, struct sockaddr_storage *local_ip)
 
conn_udp_tconn_udp_new (config_t *cfg, int family)
 
void conn_udp_vectors_reset (conn_udp_t *conn_udp)
 
static int listener_start (config_t *cfg, int family, int protocol, int *err_no)
 
conn_tconn_listener_provision (config_t *cfg, int family, int protocol, char *err_buf, size_t err_buf_len)
 
void conn_fifo_enqueue_read (conn_fifo_queue_t *queue, conn_t *conn)
 
conn_tconn_fifo_dequeue_read (conn_fifo_queue_t *queue)
 
void conn_fifo_enqueue_gen (conn_fifo_queue_t *queue, conn_t *conn)
 
conn_tconn_fifo_dequeue_gen (conn_fifo_queue_t *queue)
 
void conn_fifo_enqueue_write (conn_fifo_queue_t *queue, conn_t *conn)
 
conn_tconn_fifo_dequeue_write (conn_fifo_queue_t *queue)
 
void conn_fifo_enqueue_release (conn_fifo_queue_t *queue, conn_t *conn)
 
conn_tconn_fifo_dequeue_release (conn_fifo_queue_t *queue)
 
void conn_fifo_remove_from_read_queue (conn_fifo_queue_t *queue, conn_t *conn_rm)
 
void conn_fifo_remove_from_write_queue (conn_fifo_queue_t *queue, conn_t *conn_rm)
 
conn_tconn_lru_cache_get (conn_t **lru, uint64_t id)
 
bool conn_tcp_id_assign (uint64_t *id, conn_t **lru, uint64_t *base)
 

Detailed Description

Author
Faruk Grozdanic

Copyright (c) 2025 Faruk Grozdanic

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Function Documentation

◆ listener_err_to_str()

static char * listener_err_to_str ( int  err)
static

Function returns string matching a listener error enumerated by listener_start_error_t.

Parameters
errID to return string message for.
Returns
String matching error id. String returned is a constant.
Here is the caller graph for this function:

◆ listener_start()

static int listener_start ( config_t cfg,
int  family,
int  protocol,
int *  err_no 
)
static

Start a TCP or UDP DNS listener.

Starts a listener for given IP family and protocol. Socket is created and socket options set. If protocol is TCP listen() is called to start listening for new TCP connections on socket.

Parameters
cfgConfiguration object that has settings:
  • tcp_listener_port,
  • tcp_writebuff_size,
  • tcp_listener_port, -tcp_listener_pending_conns_max,
  • udp_socket_recvbuff_size,
  • udp_socket_sendbuff_size,
  • udp_listener_port.
familyIP family to start a listener for, valid options are:
  • AF_INET,
  • AF_INET6.
protocolProtocol to start listener for, valid options are:
  • IPPROTO_TCP,
  • IPPROTO_UDP.
err_noWhere to store value of errno if error was encountered.
Returns
On success returns a socket descriptor for started listener. On error returns negative number representing error. Errors are of enum type listener_start_error_t: typedef enum listener_start_error_e { LISTENER_ERR_SOCKET = -1, LISTENER_ERR_SOCKET_OPT_REUSEADDR = -2, LISTENER_ERR_SOCKET_OPT_REUSEPORT = -3, LISTENER_ERR_BIND = -4, LISTENER_ERR_LISTEN = -5, LISTENER_ERR_MALLOC = -6, LISTENER_ERR_SOCKET_OPT_IP_PKTINFO = -7, LISTENER_ERR_SOCKET_OPT_IPV6_V6ONLY = -8, LISTENER_ERR_SOCKET_OPT_IPV6_RECVPKTINFO = -9, } listener_start_error_t;
Here is the caller graph for this function: