Loading...
Searching...
No Matches
Data Structures | Macros | Functions
as_socket.h File Reference
#include <aerospike/as_address.h>
#include <aerospike/as_error.h>
#include <citrusleaf/cf_clock.h>
#include <pthread.h>
#include <stddef.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <errno.h>
+ Include dependency graph for as_socket.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  as_socket
 
struct  as_tls_context
 

Macros

#define as_close(_fd)   close((_fd))
 
#define AS_CONNECTING   EINPROGRESS
 
#define as_last_error()   errno
 
#define as_socket_data_t   void
 
#define as_socket_fd   int
 
#define as_socket_size_t   size_t
 
#define AS_WOULDBLOCK   EWOULDBLOCK
 

Functions

void as_socket_close (as_socket *sock)
 
static bool as_socket_connect_fd (as_socket_fd fd, struct sockaddr *addr, socklen_t size)
 
int as_socket_create (as_socket *sock, int family, as_tls_context *ctx, const char *tls_name)
 
as_status as_socket_create_and_connect (as_socket *sock, as_error *err, struct sockaddr *addr, as_tls_context *ctx, const char *tls_name, uint64_t deadline_ms)
 
int as_socket_create_fd (int family, as_socket_fd *fdp)
 
static bool as_socket_current_tran (uint64_t last_used, uint64_t max_socket_idle_ns)
 
static bool as_socket_current_trim (uint64_t last_used, uint64_t max_socket_idle_ns)
 
static uint64_t as_socket_deadline (uint32_t timeout_ms)
 
as_status as_socket_error (as_socket_fd fd, struct as_node_s *node, as_error *err, as_status status, const char *msg, int code)
 
void as_socket_error_append (as_error *err, struct sockaddr *addr)
 
static as_tls_contextas_socket_get_tls_context (as_tls_context *ctx)
 
void as_socket_init (as_socket *sock)
 
as_status as_socket_read_deadline (as_error *err, as_socket *sock, struct as_node_s *node, uint8_t *buf, size_t buf_len, uint32_t socket_timeout, uint64_t deadline)
 
bool as_socket_start_connect (as_socket *sock, struct sockaddr *addr, uint64_t deadline_ms)
 
static bool as_socket_use_tls (as_tls_context *ctx)
 
int as_socket_validate_fd (as_socket_fd fd)
 
bool as_socket_wrap (as_socket *sock, int family, as_socket_fd fd, as_tls_context *ctx, const char *tls_name)
 
as_status as_socket_write_deadline (as_error *err, as_socket *sock, struct as_node_s *node, uint8_t *buf, size_t buf_len, uint32_t socket_timeout, uint64_t deadline)
 

Macro Definition Documentation

◆ as_close

#define as_close ( _fd)    close((_fd))

Definition at line 37 of file as_socket.h.

◆ AS_CONNECTING

#define AS_CONNECTING   EINPROGRESS

Definition at line 35 of file as_socket.h.

◆ as_last_error

#define as_last_error ( )    errno

Definition at line 38 of file as_socket.h.

◆ as_socket_data_t

#define as_socket_data_t   void

Definition at line 33 of file as_socket.h.

◆ as_socket_fd

#define as_socket_fd   int

Definition at line 32 of file as_socket.h.

◆ as_socket_size_t

#define as_socket_size_t   size_t

Definition at line 34 of file as_socket.h.

◆ AS_WOULDBLOCK

#define AS_WOULDBLOCK   EWOULDBLOCK

Definition at line 36 of file as_socket.h.

Function Documentation

◆ as_socket_close()

void as_socket_close ( as_socket * sock)
private

Close and release resources associated with a as_socket.

◆ as_socket_connect_fd()

static bool as_socket_connect_fd ( as_socket_fd fd,
struct sockaddr * addr,
socklen_t size )
inlinestaticprivate

Connect to non-blocking socket.

Definition at line 152 of file as_socket.h.

References AS_CONNECTING, and as_last_error.

◆ as_socket_create()

int as_socket_create ( as_socket * sock,
int family,
as_tls_context * ctx,
const char * tls_name )
private

Create non-blocking socket. Family should be AF_INET or AF_INET6. Return zero on success.

◆ as_socket_create_and_connect()

as_status as_socket_create_and_connect ( as_socket * sock,
as_error * err,
struct sockaddr * addr,
as_tls_context * ctx,
const char * tls_name,
uint64_t deadline_ms )
private

Create non-blocking socket and connect.

◆ as_socket_create_fd()

int as_socket_create_fd ( int family,
as_socket_fd * fdp )
private

Create non-blocking socket. Family should be AF_INET or AF_INET6. Return zero on success.

◆ as_socket_current_tran()

static bool as_socket_current_tran ( uint64_t last_used,
uint64_t max_socket_idle_ns )
inlinestaticprivate

Is socket idle within limit for transactions.

Definition at line 197 of file as_socket.h.

◆ as_socket_current_trim()

static bool as_socket_current_trim ( uint64_t last_used,
uint64_t max_socket_idle_ns )
inlinestaticprivate

Is socket idle within limit for trimming idle sockets in cluster tend thread.

Definition at line 207 of file as_socket.h.

◆ as_socket_deadline()

static uint64_t as_socket_deadline ( uint32_t timeout_ms)
inlinestaticprivate

Calculate future deadline given timeout.

Definition at line 229 of file as_socket.h.

◆ as_socket_error()

as_status as_socket_error ( as_socket_fd fd,
struct as_node_s * node,
as_error * err,
as_status status,
const char * msg,
int code )
private

Create error message for socket error.

◆ as_socket_error_append()

void as_socket_error_append ( as_error * err,
struct sockaddr * addr )
private

Append address to error message.

◆ as_socket_get_tls_context()

static as_tls_context * as_socket_get_tls_context ( as_tls_context * ctx)
inlinestaticprivate

Return TLS context only if exists and not for login only.

Definition at line 110 of file as_socket.h.

References as_tls_context::for_login_only.

◆ as_socket_init()

void as_socket_init ( as_socket * sock)
private

Initialize an as_socket structure.

◆ as_socket_read_deadline()

as_status as_socket_read_deadline ( as_error * err,
as_socket * sock,
struct as_node_s * node,
uint8_t * buf,
size_t buf_len,
uint32_t socket_timeout,
uint64_t deadline )
private

Read socket data with future deadline in milliseconds. If deadline is zero, do not set deadline.

◆ as_socket_start_connect()

bool as_socket_start_connect ( as_socket * sock,
struct sockaddr * addr,
uint64_t deadline_ms )
private

Connect to non-blocking socket and perform sync TLS connect if TLS enabled.

◆ as_socket_use_tls()

static bool as_socket_use_tls ( as_tls_context * ctx)
inlinestaticprivate

Return true if TLS context exists and not TLS login only.

Definition at line 100 of file as_socket.h.

References as_tls_context::for_login_only.

◆ as_socket_validate_fd()

int as_socket_validate_fd ( as_socket_fd fd)
private

Peek for socket connection status using underlying fd. Needed to support libuv.

Returns
0 : socket is connected, but no data available. > 0 : byte size of data available. < 0 : socket is invalid.

◆ as_socket_wrap()

bool as_socket_wrap ( as_socket * sock,
int family,
as_socket_fd fd,
as_tls_context * ctx,
const char * tls_name )
private

Wrap existing fd in a socket. Family should be AF_INET or AF_INET6.

◆ as_socket_write_deadline()

as_status as_socket_write_deadline ( as_error * err,
as_socket * sock,
struct as_node_s * node,
uint8_t * buf,
size_t buf_len,
uint32_t socket_timeout,
uint64_t deadline )
private

Write socket data with future deadline in milliseconds. If deadline is zero, do not set deadline.