TCP socket abstraction layer. More...
Data Structures | |
struct | spdk_sock_request |
Anywhere this struct is used, an iovec array is assumed to immediately follow the last member in memory, without any padding. More... | |
struct | spdk_sock_request::__sock_request_internal |
struct | spdk_sock_impl_opts |
SPDK socket implementation options. More... | |
struct | spdk_sock_opts |
Spdk socket initialization options. More... | |
Macros | |
#define | SPDK_SOCK_REQUEST_IOV(req, i) ((struct iovec *)(((uint8_t *)req + sizeof(struct spdk_sock_request)) + (sizeof(struct iovec) * i))) |
#define | SPDK_TLS_VERSION_1_1 11 |
#define | SPDK_TLS_VERSION_1_2 12 |
#define | SPDK_TLS_VERSION_1_3 13 |
#define | SPDK_SOCK_GROUP_REGISTER_INTERRUPT(sock, events, fn, arg) spdk_sock_group_register_interrupt(sock, events, fn, arg, #fn) |
Typedefs | |
typedef void(* | spdk_sock_connect_cb_fn) (void *cb_arg, int status) |
Signature for callback function invoked when a connection is completed. | |
typedef void(* | spdk_sock_cb) (void *arg, struct spdk_sock_group *group, struct spdk_sock *sock) |
Callback function for spdk_sock_group_add_sock(). | |
Enumerations | |
enum | spdk_placement_mode { PLACEMENT_NONE , PLACEMENT_NAPI , PLACEMENT_CPU , PLACEMENT_MARK } |
Functions | |
SPDK_STATIC_ASSERT (sizeof(struct spdk_sock_request)==64, "Incorrect size.") | |
SPDK_STATIC_ASSERT (sizeof(struct spdk_sock_opts)==56, "Incorrect size") | |
void | spdk_sock_get_default_opts (struct spdk_sock_opts *opts) |
Initialize the default value of opts. | |
int | spdk_sock_getaddr (struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport, char *caddr, int clen, uint16_t *cport) |
Get client and server addresses of the given socket. | |
const char * | spdk_sock_get_impl_name (struct spdk_sock *sock) |
Get socket implementation name. | |
struct spdk_sock * | spdk_sock_connect (const char *ip, int port, const char *impl_name) |
Create a socket using the specific sock implementation, connect the socket to the specified address and port (of the server), and then return the socket. | |
struct spdk_sock * | spdk_sock_connect_ext (const char *ip, int port, const char *impl_name, struct spdk_sock_opts *opts) |
Create a socket using the specific sock implementation, connect the socket to the specified address and port (of the server), and then return the socket. | |
struct spdk_sock * | spdk_sock_connect_async (const char *ip, int port, const char *impl_name, struct spdk_sock_opts *opts, spdk_sock_connect_cb_fn cb_fn, void *cb_arg) |
Create a socket using the specific sock implementation, initiate the socket connection to the specified address and port (of the server), and then return the socket. | |
struct spdk_sock * | spdk_sock_listen (const char *ip, int port, const char *impl_name) |
Create a socket using the specific sock implementation, bind the socket to the specified address and port and listen on the socket, and then return the socket. | |
struct spdk_sock * | spdk_sock_listen_ext (const char *ip, int port, const char *impl_name, struct spdk_sock_opts *opts) |
Create a socket using the specific sock implementation, bind the socket to the specified address and port and listen on the socket, and then return the socket. | |
struct spdk_sock * | spdk_sock_accept (struct spdk_sock *sock) |
Accept a new connection from a client on the specified socket and return a socket structure which holds the connection. | |
const char * | spdk_sock_get_interface_name (struct spdk_sock *sock) |
Gets the name of the network interface of the local port for the socket. | |
int32_t | spdk_sock_get_numa_id (struct spdk_sock *sock) |
Gets the NUMA node ID for the network interface of the local port for the TCP socket. | |
int | spdk_sock_close (struct spdk_sock **sock) |
Close a socket. | |
int | spdk_sock_flush (struct spdk_sock *sock) |
Flush a socket from data gathered in previous writev_async calls. | |
ssize_t | spdk_sock_recv (struct spdk_sock *sock, void *buf, size_t len) |
Receive a message from the given socket. | |
ssize_t | spdk_sock_writev (struct spdk_sock *sock, struct iovec *iov, int iovcnt) |
Write message to the given socket from the I/O vector array. | |
void | spdk_sock_writev_async (struct spdk_sock *sock, struct spdk_sock_request *req) |
Write data to the given socket asynchronously, calling the provided callback when the data has been written. | |
ssize_t | spdk_sock_readv (struct spdk_sock *sock, struct iovec *iov, int iovcnt) |
Read message from the given socket to the I/O vector array. | |
int | spdk_sock_recv_next (struct spdk_sock *sock, void **buf, void **ctx) |
Receive the next portion of the stream from the socket. | |
int | spdk_sock_set_recvlowat (struct spdk_sock *sock, int nbytes) |
Set the value used to specify the low water mark (in bytes) for this socket. | |
int | spdk_sock_set_recvbuf (struct spdk_sock *sock, int sz) |
Set receive buffer size for the given socket. | |
int | spdk_sock_set_sendbuf (struct spdk_sock *sock, int sz) |
Set send buffer size for the given socket. | |
bool | spdk_sock_is_ipv6 (struct spdk_sock *sock) |
Check whether the address of socket is ipv6. | |
bool | spdk_sock_is_ipv4 (struct spdk_sock *sock) |
Check whether the address of socket is ipv4. | |
bool | spdk_sock_is_connected (struct spdk_sock *sock) |
Check whether the socket is currently connected. | |
struct spdk_sock_group * | spdk_sock_group_create (void *ctx) |
Create a new socket group with user provided pointer. | |
void * | spdk_sock_group_get_ctx (struct spdk_sock_group *sock_group) |
Get the ctx of the sock group. | |
int | spdk_sock_group_add_sock (struct spdk_sock_group *group, struct spdk_sock *sock, spdk_sock_cb cb_fn, void *cb_arg) |
Add a socket to the group. | |
int | spdk_sock_group_remove_sock (struct spdk_sock_group *group, struct spdk_sock *sock) |
Remove a socket from the group. | |
int | spdk_sock_group_provide_buf (struct spdk_sock_group *group, void *buf, size_t len, void *ctx) |
Provides a buffer to the group to be used in its receive pool. | |
int | spdk_sock_group_poll (struct spdk_sock_group *group) |
Poll incoming events for each registered socket. | |
int | spdk_sock_group_poll_count (struct spdk_sock_group *group, int max_events) |
Poll incoming events up to max_events for each registered socket. | |
int | spdk_sock_group_close (struct spdk_sock_group **group) |
Close all registered sockets of the group and then remove the group. | |
int | spdk_sock_get_optimal_sock_group (struct spdk_sock *sock, struct spdk_sock_group **group, struct spdk_sock_group *hint) |
Get the optimal sock group for this sock. | |
int | spdk_sock_impl_get_opts (const char *impl_name, struct spdk_sock_impl_opts *opts, size_t *len) |
Get current socket implementation options. | |
int | spdk_sock_impl_set_opts (const char *impl_name, const struct spdk_sock_impl_opts *opts, size_t len) |
Set socket implementation options. | |
int | spdk_sock_set_default_impl (const char *impl_name) |
Set the given sock implementation to be used as the default one. | |
const char * | spdk_sock_get_default_impl (void) |
Get the name of the current default implementation. | |
void | spdk_sock_write_config_json (struct spdk_json_write_ctx *w) |
Write socket subsystem configuration into provided JSON context. | |
int | spdk_sock_group_register_interrupt (struct spdk_sock_group *group, uint32_t events, spdk_interrupt_fn fn, void *arg, const char *name) |
Register an spdk_interrupt with specific event types on the current thread for the given socket group. | |
void | spdk_sock_group_unregister_interrupt (struct spdk_sock_group *group) |
Unregister an spdk_interrupt for the given socket group from the current thread. | |
TCP socket abstraction layer.
typedef void(* spdk_sock_cb) (void *arg, struct spdk_sock_group *group, struct spdk_sock *sock) |
Callback function for spdk_sock_group_add_sock().
arg | Argument for the callback function. |
group | Socket group. |
sock | Socket. |
typedef void(* spdk_sock_connect_cb_fn) (void *cb_arg, int status) |
Signature for callback function invoked when a connection is completed.
cb_arg | Context specified by spdk_sock_connect_async. |
status | 0 on success, negative errno value on failure. |
struct spdk_sock * spdk_sock_accept | ( | struct spdk_sock * | sock | ) |
Accept a new connection from a client on the specified socket and return a socket structure which holds the connection.
sock | Listening socket. |
int spdk_sock_close | ( | struct spdk_sock ** | sock | ) |
Close a socket.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to close. |
struct spdk_sock * spdk_sock_connect | ( | const char * | ip, |
int | port, | ||
const char * | impl_name ) |
Create a socket using the specific sock implementation, connect the socket to the specified address and port (of the server), and then return the socket.
This function is used by client.
ip | IP address of the server. |
port | Port number of the server. |
impl_name | The sock implementation to use, such as "posix", or NULL for default. |
struct spdk_sock * spdk_sock_connect_async | ( | const char * | ip, |
int | port, | ||
const char * | impl_name, | ||
struct spdk_sock_opts * | opts, | ||
spdk_sock_connect_cb_fn | cb_fn, | ||
void * | cb_arg ) |
Create a socket using the specific sock implementation, initiate the socket connection to the specified address and port (of the server), and then return the socket.
This function is used by client.
Not every function with sock object on the interface is allowed if the conncection is not established. In order to determine connection status use cb_fn
. Functions taking sock object as an input may return EAGAIN to indicate connection is in progress or other errno values if connection failed.
Callback function cb_fn
is invoked only if this function returns a non-NULL value. If async connect is not supported by the impl_name
specified then NULL is returned.
ip | IP address of the server. |
port | Port number of the server. |
impl_name | The sock implementation to use, such as "posix", or NULL for default. |
opts | The sock option pointer provided by the user which should not be NULL pointer. |
cb_fn | Callback function invoked when the connection attempt is completed. (optional) |
cb_arg | Argument passed to callback function. (optional) |
struct spdk_sock * spdk_sock_connect_ext | ( | const char * | ip, |
int | port, | ||
const char * | impl_name, | ||
struct spdk_sock_opts * | opts ) |
Create a socket using the specific sock implementation, connect the socket to the specified address and port (of the server), and then return the socket.
This function is used by client.
ip | IP address of the server. |
port | Port number of the server. |
impl_name | The sock implementation to use, such as "posix", or NULL for default. |
opts | The sock option pointer provided by the user which should not be NULL pointer. |
int spdk_sock_flush | ( | struct spdk_sock * | sock | ) |
Flush a socket from data gathered in previous writev_async calls.
On failure check errno matching EAGAIN to determine failure is retryable.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to flush. |
const char * spdk_sock_get_default_impl | ( | void | ) |
Get the name of the current default implementation.
void spdk_sock_get_default_opts | ( | struct spdk_sock_opts * | opts | ) |
Initialize the default value of opts.
opts | Data structure where SPDK will initialize the default sock options. Users must set opts_size to sizeof(struct spdk_sock_opts). This will ensure that the libraryonly tries to fill as many fields as allocated by the caller. This allows ABI compatibility with future versions of this library that may extend the spdk_sock_opts structure. |
const char * spdk_sock_get_impl_name | ( | struct spdk_sock * | sock | ) |
Get socket implementation name.
sock | Pointer to SPDK socket. |
const char * spdk_sock_get_interface_name | ( | struct spdk_sock * | sock | ) |
Gets the name of the network interface of the local port for the socket.
sock | socket to find the interface name for |
int32_t spdk_sock_get_numa_id | ( | struct spdk_sock * | sock | ) |
Gets the NUMA node ID for the network interface of the local port for the TCP socket.
sock | TCP socket to find the NUMA socket ID for |
int spdk_sock_get_optimal_sock_group | ( | struct spdk_sock * | sock, |
struct spdk_sock_group ** | group, | ||
struct spdk_sock_group * | hint ) |
Get the optimal sock group for this sock.
This function is allowed only when connection is established.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | The socket |
group | Returns the optimal sock group. If there is no optimal sock group, returns NULL. |
hint | When return is 0 and group is set to NULL, hint is used to set optimal sock group for the socket. |
int spdk_sock_getaddr | ( | struct spdk_sock * | sock, |
char * | saddr, | ||
int | slen, | ||
uint16_t * | sport, | ||
char * | caddr, | ||
int | clen, | ||
uint16_t * | cport ) |
Get client and server addresses of the given socket.
This function is allowed only when connection is established.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to get address. |
saddr | A pointer to the buffer to hold the address of server. |
slen | Length of the buffer 'saddr'. |
sport | A pointer(May be NULL) to the buffer to hold the port info of server. |
caddr | A pointer to the buffer to hold the address of client. |
clen | Length of the buffer 'caddr'. |
cport | A pointer(May be NULL) to the buffer to hold the port info of server. |
int spdk_sock_group_add_sock | ( | struct spdk_sock_group * | group, |
struct spdk_sock * | sock, | ||
spdk_sock_cb | cb_fn, | ||
void * | cb_arg ) |
Add a socket to the group.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
group | Socket group. |
sock | Socket to add. |
cb_fn | Called when the operation completes. |
cb_arg | Argument passed to the callback function. |
int spdk_sock_group_close | ( | struct spdk_sock_group ** | group | ) |
Close all registered sockets of the group and then remove the group.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
If any sockets were added to the group by spdk_sock_group_add_sock these must be removed first by using spdk_sock_group_remove_sock.
group | Group to close. |
struct spdk_sock_group * spdk_sock_group_create | ( | void * | ctx | ) |
Create a new socket group with user provided pointer.
ctx | the context provided by user. |
void * spdk_sock_group_get_ctx | ( | struct spdk_sock_group * | sock_group | ) |
Get the ctx of the sock group.
sock_group | Socket group. |
int spdk_sock_group_poll | ( | struct spdk_sock_group * | group | ) |
Poll incoming events for each registered socket.
group | Group to poll. |
int spdk_sock_group_poll_count | ( | struct spdk_sock_group * | group, |
int | max_events ) |
Poll incoming events up to max_events for each registered socket.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
group | Group to poll. |
max_events | Number of maximum events to poll for each socket. |
int spdk_sock_group_provide_buf | ( | struct spdk_sock_group * | group, |
void * | buf, | ||
size_t | len, | ||
void * | ctx ) |
Provides a buffer to the group to be used in its receive pool.
See spdk_sock_recv_next() for more details.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
group | Socket group. |
buf | Pointer the buffer provided. |
len | Length of the buffer. |
ctx | Pointer that will be returned in spdk_sock_recv_next() |
int spdk_sock_group_register_interrupt | ( | struct spdk_sock_group * | group, |
uint32_t | events, | ||
spdk_interrupt_fn | fn, | ||
void * | arg, | ||
const char * | name ) |
Register an spdk_interrupt with specific event types on the current thread for the given socket group.
Returning non-zero is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
The provided function will be called any time one of specified event types triggers on the associated file descriptor. Event types argument is a bit mask composed by ORing together enum spdk_interrupt_event_types values.
group | Socket group. |
events | Event notification types. |
fn | Called each time there are events in spdk_interrupt. |
arg | Function argument for fn. |
name | Human readable name for the spdk_interrupt. |
int spdk_sock_group_remove_sock | ( | struct spdk_sock_group * | group, |
struct spdk_sock * | sock ) |
Remove a socket from the group.
group | Socket group. |
sock | Socket to remove. |
void spdk_sock_group_unregister_interrupt | ( | struct spdk_sock_group * | group | ) |
Unregister an spdk_interrupt for the given socket group from the current thread.
group | Socket group. |
int spdk_sock_impl_get_opts | ( | const char * | impl_name, |
struct spdk_sock_impl_opts * | opts, | ||
size_t * | len ) |
Get current socket implementation options.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
impl_name | The socket implementation to use, such as "posix". |
opts | Pointer to allocated spdk_sock_impl_opts structure that will be filled with actual values. |
len | On input specifies size of passed opts structure. On return it is set to actual size that was filled with values. |
int spdk_sock_impl_set_opts | ( | const char * | impl_name, |
const struct spdk_sock_impl_opts * | opts, | ||
size_t | len ) |
Set socket implementation options.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
impl_name | The socket implementation to use, such as "posix". |
opts | Pointer to allocated spdk_sock_impl_opts structure with new options values. |
len | Size of passed opts structure. |
bool spdk_sock_is_connected | ( | struct spdk_sock * | sock | ) |
Check whether the socket is currently connected.
sock | Socket to check |
bool spdk_sock_is_ipv4 | ( | struct spdk_sock * | sock | ) |
Check whether the address of socket is ipv4.
This function is allowed only when connection is established.
sock | Socket to check. |
bool spdk_sock_is_ipv6 | ( | struct spdk_sock * | sock | ) |
Check whether the address of socket is ipv6.
This function is allowed only when connection is established.
sock | Socket to check. |
struct spdk_sock * spdk_sock_listen | ( | const char * | ip, |
int | port, | ||
const char * | impl_name ) |
Create a socket using the specific sock implementation, bind the socket to the specified address and port and listen on the socket, and then return the socket.
This function is used by server.
ip | IP address to listen on. |
port | Port number. |
impl_name | The sock implementation to use, such as "posix", or NULL for default. |
struct spdk_sock * spdk_sock_listen_ext | ( | const char * | ip, |
int | port, | ||
const char * | impl_name, | ||
struct spdk_sock_opts * | opts ) |
Create a socket using the specific sock implementation, bind the socket to the specified address and port and listen on the socket, and then return the socket.
This function is used by server.
ip | IP address to listen on. |
port | Port number. |
impl_name | The sock implementation to use, such as "posix", or NULL for default. |
opts | The sock option pointer provided by the user, which should not be NULL pointer. |
ssize_t spdk_sock_readv | ( | struct spdk_sock * | sock, |
struct iovec * | iov, | ||
int | iovcnt ) |
Read message from the given socket to the I/O vector array.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to receive message. |
iov | I/O vector. |
iovcnt | Number of I/O vectors in the array. |
ssize_t spdk_sock_recv | ( | struct spdk_sock * | sock, |
void * | buf, | ||
size_t | len ) |
Receive a message from the given socket.
On failure check errno matching EAGAIN to determine failure is retryable.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to receive message. |
buf | Pointer to a buffer to hold the data. |
len | Length of the buffer. |
int spdk_sock_recv_next | ( | struct spdk_sock * | sock, |
void ** | buf, | ||
void ** | ctx ) |
Receive the next portion of the stream from the socket.
A buffer provided to this socket's group's pool using spdk_sock_group_provide_buf() will contain the data and be returned in *buf.
Note that the amount of data in buf is determined entirely by the sock layer. You cannot request to receive only a limited amount here. You simply get whatever the next portion of the stream is, as determined by the sock module. You can place an upper limit on the size of the buffer since these buffers are originally provided to the group through spdk_sock_group_provide_buf().
This code path will only work if the recvbuf is disabled. To disable the recvbuf, call spdk_sock_set_recvbuf with a size of 0.
On failure check errno matching EAGAIN to determine failure is retryable.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to receive from. |
buf | Populated with the next portion of the stream |
ctx | Returned context pointer from when the buffer was provided. |
int spdk_sock_set_default_impl | ( | const char * | impl_name | ) |
Set the given sock implementation to be used as the default one.
Note: passing a specific sock implementation name in some sock API functions (such as spdk_sock_connect, spdk_sock_listen and etc) ignores the default value set by this function.
impl_name | The socket implementation to use, such as "posix". |
int spdk_sock_set_recvbuf | ( | struct spdk_sock * | sock, |
int | sz ) |
Set receive buffer size for the given socket.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to set buffer size for. |
sz | Buffer size in bytes. |
int spdk_sock_set_recvlowat | ( | struct spdk_sock * | sock, |
int | nbytes ) |
Set the value used to specify the low water mark (in bytes) for this socket.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to set for. |
nbytes | Value for recvlowat. |
int spdk_sock_set_sendbuf | ( | struct spdk_sock * | sock, |
int | sz ) |
Set send buffer size for the given socket.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to set buffer size for. |
sz | Buffer size in bytes. |
void spdk_sock_write_config_json | ( | struct spdk_json_write_ctx * | w | ) |
Write socket subsystem configuration into provided JSON context.
w | JSON write context |
ssize_t spdk_sock_writev | ( | struct spdk_sock * | sock, |
struct iovec * | iov, | ||
int | iovcnt ) |
Write message to the given socket from the I/O vector array.
On failure check errno matching EAGAIN to determine failure is retryable.
Returning -1 and setting errno is deprecated and will be changed in the 26.01 release. This function will return negative errno values instead.
sock | Socket to write to. |
iov | I/O vector. |
iovcnt | Number of I/O vectors in the array. |
void spdk_sock_writev_async | ( | struct spdk_sock * | sock, |
struct spdk_sock_request * | req ) |
Write data to the given socket asynchronously, calling the provided callback when the data has been written.
sock | Socket to write to. |
req | The write request to submit. |