libosmocore 1.9.0.186-fab9.202403172026
Osmocom core library
|
io(_uring) abstraction osmo fd compatibility More...
#include <sys/socket.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/utils.h>
Go to the source code of this file.
Data Structures | |
struct | osmo_io_ops |
Macros | |
#define | LOGPIO(iofd, level, fmt, args...) LOGP(DLIO, level, "iofd(%s)" fmt, iofd->name, ## args) |
Enumerations | |
enum | osmo_io_fd_mode { OSMO_IO_FD_MODE_READ_WRITE , OSMO_IO_FD_MODE_RECVFROM_SENDTO , OSMO_IO_FD_MODE_RECVMSG_SENDMSG } |
enum | osmo_io_backend { OSMO_IO_BACKEND_POLL , OSMO_IO_BACKEND_IO_URING } |
Functions | |
static const char * | osmo_io_backend_name (enum osmo_io_backend val) |
static const char * | osmo_iofd_mode_name (enum osmo_io_fd_mode val) |
void | osmo_iofd_init (void) |
initialize osmo_io for the current thread More... | |
struct osmo_io_fd * | osmo_iofd_setup (const void *ctx, int fd, const char *name, enum osmo_io_fd_mode mode, const struct osmo_io_ops *ioops, void *data) |
Allocate and setup a new iofd. More... | |
int | osmo_iofd_set_cmsg_size (struct osmo_io_fd *iofd, size_t cmsg_size) |
Set the size of the control message buffer allocated when submitting recvmsg. More... | |
int | osmo_iofd_register (struct osmo_io_fd *iofd, int fd) |
Register the fd with the underlying backend. More... | |
int | osmo_iofd_unregister (struct osmo_io_fd *iofd) |
Unregister the fd from the underlying backend. More... | |
unsigned int | osmo_iofd_txqueue_len (struct osmo_io_fd *iofd) |
Get the number of messages in the tx queue. More... | |
void | osmo_iofd_txqueue_clear (struct osmo_io_fd *iofd) |
Clear the transmit queue of the the iofd. More... | |
int | osmo_iofd_close (struct osmo_io_fd *iofd) |
Close the iofd. More... | |
void | osmo_iofd_free (struct osmo_io_fd *iofd) |
Free the iofd. More... | |
void | osmo_iofd_notify_connected (struct osmo_io_fd *iofd) |
Notify the user if/when the socket is connected. More... | |
int | osmo_iofd_write_msgb (struct osmo_io_fd *iofd, struct msgb *msg) |
Send a message through a connected socket. More... | |
int | osmo_iofd_sendto_msgb (struct osmo_io_fd *iofd, struct msgb *msg, int sendto_flags, const struct osmo_sockaddr *dest) |
Send a message through an unconnected socket. More... | |
int | osmo_iofd_sendmsg_msgb (struct osmo_io_fd *iofd, struct msgb *msg, int sendmsg_flags, const struct msghdr *msgh) |
ismo_io equivalent of the sendmsg(2) socket API call More... | |
void | osmo_iofd_set_alloc_info (struct osmo_io_fd *iofd, unsigned int size, unsigned int headroom) |
Set the size and headroom of the msgb allocated when receiving messages. More... | |
void | osmo_iofd_set_txqueue_max_length (struct osmo_io_fd *iofd, unsigned int size) |
Set the maximum number of messages enqueued for sending. More... | |
void * | osmo_iofd_get_data (const struct osmo_io_fd *iofd) |
Get the associated user-data from an iofd. More... | |
void | osmo_iofd_set_data (struct osmo_io_fd *iofd, void *data) |
Set the associated user-data from an iofd. More... | |
unsigned int | osmo_iofd_get_priv_nr (const struct osmo_io_fd *iofd) |
Get the private number from an iofd. More... | |
void | osmo_iofd_set_priv_nr (struct osmo_io_fd *iofd, unsigned int priv_nr) |
Set the private number from an iofd. More... | |
int | osmo_iofd_get_fd (const struct osmo_io_fd *iofd) |
Get the underlying file descriptor from an iofd. More... | |
const char * | osmo_iofd_get_name (const struct osmo_io_fd *iofd) |
Get the name of the file descriptor. More... | |
void | osmo_iofd_set_name (struct osmo_io_fd *iofd, const char *name) |
Set the name of the file descriptor. More... | |
int | osmo_iofd_set_ioops (struct osmo_io_fd *iofd, const struct osmo_io_ops *ioops) |
Set the osmo_io_ops for an iofd. More... | |
void | osmo_iofd_get_ioops (struct osmo_io_fd *iofd, struct osmo_io_ops *ioops) |
Get the osmo_io_ops for an iofd. More... | |
Variables | |
const struct value_string | osmo_io_backend_names [] |
const struct value_string | osmo_iofd_mode_names [] |
io(_uring) abstraction osmo fd compatibility
enum osmo_io_backend |
enum osmo_io_fd_mode |
|
inlinestatic |
References get_value_string(), and osmo_io_backend_names.
int osmo_iofd_close | ( | struct osmo_io_fd * | iofd | ) |
Close the iofd.
This function closes the underlying fd and clears any messages in the tx queue The iofd is not freed and can be assigned a new file descriptor with osmo_iofd_register()
[in] | iofd | the file descriptor \ returns 0 on success, a negative value otherwise |
References iofd_backend_ops::close, osmo_io_fd::fd, iofd_msghdr::iofd, IOFD_FLAG_CLOSED, IOFD_FLAG_ISSET, IOFD_FLAG_SET, msgb_free(), osmo_iofd_ops, osmo_iofd_txqueue_clear(), and osmo_io_fd::pending.
Referenced by osmo_iofd_free().
void osmo_iofd_free | ( | struct osmo_io_fd * | iofd | ) |
Free the iofd.
This function is safe to use in the read/write callbacks and will defer freeing it until safe to do so. The iofd will be closed before.
[in] | iofd | the file descriptor |
References iofd_msghdr::iofd, IOFD_FLAG_IN_CALLBACK, IOFD_FLAG_ISSET, IOFD_FLAG_SET, IOFD_FLAG_TO_FREE, and osmo_iofd_close().
void * osmo_iofd_get_data | ( | const struct osmo_io_fd * | iofd | ) |
Get the associated user-data from an iofd.
[in] | iofd | the file descriptor |
References osmo_io_fd::data, and iofd_msghdr::iofd.
int osmo_iofd_get_fd | ( | const struct osmo_io_fd * | iofd | ) |
Get the underlying file descriptor from an iofd.
[in] | iofd | the file descriptor |
References osmo_io_fd::fd, and iofd_msghdr::iofd.
void osmo_iofd_get_ioops | ( | struct osmo_io_fd * | iofd, |
struct osmo_io_ops * | ioops | ||
) |
Get the osmo_io_ops for an iofd.
[in] | iofd | Target iofd file descriptor |
[in] | ioops | caller-allocated osmo_io_ops structure to be filled |
References osmo_io_fd::io_ops, and iofd_msghdr::iofd.
const char * osmo_iofd_get_name | ( | const struct osmo_io_fd * | iofd | ) |
Get the name of the file descriptor.
[in] | iofd | the file descriptor |
References iofd_msghdr::iofd, and osmo_io_fd::name.
unsigned int osmo_iofd_get_priv_nr | ( | const struct osmo_io_fd * | iofd | ) |
Get the private number from an iofd.
[in] | iofd | the file descriptor |
References iofd_msghdr::iofd, and osmo_io_fd::priv_nr.
void osmo_iofd_init | ( | void | ) |
initialize osmo_io for the current thread
References g_io_backend, OSMO_ASSERT, OSMO_IO_BACKEND_IO_URING, and OSMO_IO_BACKEND_POLL.
Referenced by __attribute__().
|
inlinestatic |
References get_value_string(), and osmo_iofd_mode_names.
Referenced by osmo_iofd_set_ioops(), and osmo_iofd_setup().
void osmo_iofd_notify_connected | ( | struct osmo_io_fd * | iofd | ) |
Notify the user if/when the socket is connected.
When the socket is connected the write_cb will be called.
[in] | iofd | the file descriptor |
References iofd_msghdr::iofd, osmo_io_fd::mode, iofd_backend_ops::notify_connected, OSMO_ASSERT, OSMO_IO_FD_MODE_READ_WRITE, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, and osmo_iofd_ops.
int osmo_iofd_register | ( | struct osmo_io_fd * | iofd, |
int | fd | ||
) |
Register the fd with the underlying backend.
[in] | iofd | the iofd file descriptor |
[in] | fd | the system fd number that will be registeres. If negative will use the one already set. |
References osmo_io_fd::current_length, osmo_io_fd::fd, osmo_io_fd::io_ops, IOFD_FLAG_CLOSED, IOFD_FLAG_UNSET, LOGL_ERROR, LOGPIO, osmo_io_fd::mode, OSMO_IO_FD_MODE_READ_WRITE, OSMO_IO_FD_MODE_RECVFROM_SENDTO, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, osmo_iofd_ops, osmo_io_ops::read_cb, iofd_backend_ops::read_enable, osmo_io_ops::recvfrom_cb, osmo_io_ops::recvmsg_cb, iofd_backend_ops::register_fd, osmo_io_fd::tx_queue, and iofd_backend_ops::write_enable.
int osmo_iofd_sendmsg_msgb | ( | struct osmo_io_fd * | iofd, |
struct msgb * | msg, | ||
int | sendmsg_flags, | ||
const struct msghdr * | msgh | ||
) |
ismo_io equivalent of the sendmsg(2) socket API call
Appends the message to the internal transmit queue. If the function returns success (0), it will take ownership of the msgb and internally call msgb_free() after the write request completes. In case of an error the msgb needs to be freed by the caller.
[in] | iofd | file descriptor to write to |
[in] | msg | message buffer to send; is used to fill msgh->iov[] |
[in] | sendmsg_flags | Flags to pass to the send call |
[in] | msgh | 'struct msghdr' for name/control/flags. iov must be empty! |
References iofd_msghdr::cmsg, iofd_msghdr::hdr, osmo_io_fd::io_ops, iofd_msghdr::iofd, IOFD_ACT_SENDMSG, iofd_msghdr_alloc(), iofd_msghdr_free(), iofd_txqueue_enqueue(), iofd_msghdr::iov, LOGL_ERROR, LOGPIO, osmo_io_fd::mode, iofd_msghdr::msg, msgb_data(), msgb_length(), iofd_msghdr::osa, OSMO_ASSERT, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, OSMO_UNLIKELY, osmo_sockaddr::sa, osmo_io_ops::sendmsg_cb, and osmo_sockaddr::u.
int osmo_iofd_sendto_msgb | ( | struct osmo_io_fd * | iofd, |
struct msgb * | msg, | ||
int | sendto_flags, | ||
const struct osmo_sockaddr * | dest | ||
) |
Send a message through an unconnected socket.
Appends the message to the internal transmit queue. If the function returns success (0), it will take ownership of the msgb and internally call msgb_free() after the write request completes. In case of an error the msgb needs to be freed by the caller.
[in] | iofd | file descriptor to write to |
[in] | msg | message buffer to send |
[in] | sendto_flags | Flags to pass to the send call |
[in] | dest | destination address to send the message to |
References iofd_msghdr::flags, iofd_msghdr::hdr, osmo_io_fd::io_ops, iofd_msghdr::iofd, IOFD_ACT_SENDTO, iofd_msghdr_alloc(), iofd_msghdr_free(), iofd_txqueue_enqueue(), iofd_msghdr::iov, LOGL_ERROR, LOGPIO, osmo_io_fd::mode, iofd_msghdr::msg, msgb_data(), msgb_length(), iofd_msghdr::osa, OSMO_ASSERT, OSMO_IO_FD_MODE_RECVFROM_SENDTO, osmo_sockaddr_size(), OSMO_UNLIKELY, osmo_sockaddr::sa, osmo_io_ops::sendto_cb, and osmo_sockaddr::u.
void osmo_iofd_set_alloc_info | ( | struct osmo_io_fd * | iofd, |
unsigned int | size, | ||
unsigned int | headroom | ||
) |
Set the size and headroom of the msgb allocated when receiving messages.
[in] | iofd | the file descriptor |
[in] | size | the size of the msgb when receiving data |
[in] | headroom | the headroom of the msgb when receiving data |
References osmo_io_fd::headroom, iofd_msghdr::iofd, osmo_io_fd::msgb_alloc, and osmo_io_fd::size.
int osmo_iofd_set_cmsg_size | ( | struct osmo_io_fd * | iofd, |
size_t | cmsg_size | ||
) |
Set the size of the control message buffer allocated when submitting recvmsg.
References osmo_io_fd::cmsg_size, osmo_io_fd::mode, and OSMO_IO_FD_MODE_RECVMSG_SENDMSG.
void osmo_iofd_set_data | ( | struct osmo_io_fd * | iofd, |
void * | data | ||
) |
Set the associated user-data from an iofd.
[in] | iofd | the file descriptor |
[in] | data | the data to set |
References data, osmo_io_fd::data, and iofd_msghdr::iofd.
int osmo_iofd_set_ioops | ( | struct osmo_io_fd * | iofd, |
const struct osmo_io_ops * | ioops | ||
) |
Set the osmo_io_ops for an iofd.
[in] | iofd | Target iofd file descriptor |
[in] | ioops | osmo_io_ops structure to be set |
References check_mode_callback_compat(), osmo_io_fd::io_ops, iofd_msghdr::iofd, LOGL_ERROR, LOGPIO, osmo_io_fd::mode, OSMO_ASSERT, OSMO_IO_FD_MODE_READ_WRITE, OSMO_IO_FD_MODE_RECVFROM_SENDTO, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, osmo_iofd_mode_name(), osmo_iofd_ops, osmo_io_ops::read_cb, iofd_backend_ops::read_disable, iofd_backend_ops::read_enable, osmo_io_ops::recvfrom_cb, and osmo_io_ops::recvmsg_cb.
void osmo_iofd_set_name | ( | struct osmo_io_fd * | iofd, |
const char * | name | ||
) |
Set the name of the file descriptor.
[in] | iofd | the file descriptor |
[in] | name | the name to set on the file descriptor |
References iofd_msghdr::iofd, name, osmo_io_fd::name, and osmo_talloc_replace_string().
void osmo_iofd_set_priv_nr | ( | struct osmo_io_fd * | iofd, |
unsigned int | priv_nr | ||
) |
Set the private number from an iofd.
[in] | iofd | the file descriptor |
[in] | priv_nr | the private number to set |
References iofd_msghdr::iofd, and osmo_io_fd::priv_nr.
void osmo_iofd_set_txqueue_max_length | ( | struct osmo_io_fd * | iofd, |
unsigned int | max_length | ||
) |
Set the maximum number of messages enqueued for sending.
[in] | iofd | the file descriptor |
[in] | size | the maximum size of the transmit queue |
References iofd_msghdr::iofd, osmo_io_fd::max_length, and osmo_io_fd::tx_queue.
struct osmo_io_fd * osmo_iofd_setup | ( | const void * | ctx, |
int | fd, | ||
const char * | name, | ||
enum osmo_io_fd_mode | mode, | ||
const struct osmo_io_ops * | ioops, | ||
void * | data | ||
) |
Allocate and setup a new iofd.
[in] | ctx | the parent context from which to allocate |
[in] | fd | the underlying system file descriptor |
[in] | name | the name of the iofd |
[in] | mode | the mode of the iofd, whether it should use read()/write(), sendto()/recvfrom() |
[in] | ioops | structure with read/write/send/recv callbacks |
[in] | data | user data pointer accessible by the ioops callbacks |
References check_mode_callback_compat(), osmo_io_fd::ctx, data, osmo_io_fd::data, DLIO, osmo_io_fd::fd, osmo_io_fd::headroom, INIT_LLIST_HEAD, osmo_io_fd::io_ops, IOFD_FLAG_CLOSED, IOFD_FLAG_SET, LOGL_ERROR, LOGP, osmo_io_fd::max_length, osmo_io_fd::mode, osmo_io_fd::msg_queue, osmo_io_fd::msgb_alloc, name, osmo_io_fd::name, OSMO_IO_DEFAULT_MSGB_HEADROOM, OSMO_IO_DEFAULT_MSGB_SIZE, OSMO_IO_FD_MODE_READ_WRITE, OSMO_IO_FD_MODE_RECVFROM_SENDTO, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, osmo_iofd_mode_name(), osmo_io_fd::pending, osmo_io_fd::size, and osmo_io_fd::tx_queue.
void osmo_iofd_txqueue_clear | ( | struct osmo_io_fd * | iofd | ) |
Clear the transmit queue of the the iofd.
This function frees all messages currently pending in the transmit queue
[in] | iofd | the file descriptor |
References iofd_msghdr::hdr, iofd_msghdr::iofd, iofd_msghdr_free(), iofd_txqueue_dequeue(), and msgb_free().
Referenced by osmo_iofd_close().
unsigned int osmo_iofd_txqueue_len | ( | struct osmo_io_fd * | iofd | ) |
Get the number of messages in the tx queue.
[in] | iofd | the file descriptor |
References osmo_io_fd::current_length, and osmo_io_fd::tx_queue.
Referenced by iofd_poll_ofd_cb_recvmsg_sendmsg().
int osmo_iofd_unregister | ( | struct osmo_io_fd * | iofd | ) |
Unregister the fd from the underlying backend.
[in] | iofd | the file descriptor |
References osmo_iofd_ops, and iofd_backend_ops::unregister_fd.
int osmo_iofd_write_msgb | ( | struct osmo_io_fd * | iofd, |
struct msgb * | msg | ||
) |
Send a message through a connected socket.
Appends the message to the internal transmit queue. If the function returns success (0) it will take ownership of the msgb and internally call msgb_free() after the write request completes. In case of an error the msgb needs to be freed by the caller.
[in] | iofd | file descriptor to write to |
[in] | msg | message buffer to write |
References iofd_msghdr::flags, iofd_msghdr::hdr, osmo_io_fd::io_ops, iofd_msghdr::iofd, IOFD_ACT_WRITE, iofd_msghdr_alloc(), iofd_msghdr_free(), iofd_txqueue_enqueue(), iofd_msghdr::iov, LOGL_ERROR, LOGPIO, osmo_io_fd::mode, msg, iofd_msghdr::msg, msgb_data(), msgb_length(), OSMO_ASSERT, OSMO_IO_FD_MODE_READ_WRITE, OSMO_UNLIKELY, and osmo_io_ops::write_cb.
|
extern |
Referenced by osmo_io_backend_name().
|
extern |
Referenced by osmo_iofd_mode_name().