libosmocore 1.9.0.186-fab9.202403172026
Osmocom core library
osmo_io.c File Reference

New osmocom async I/O API. More...

#include "../config.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <talloc.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include <osmocom/core/osmo_io.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>
#include "osmo_io_internal.h"

Macros

#define OSMO_IO_BACKEND_ENV   "LIBOSMO_IO_BACKEND"
 This environment variable can be set to manually set the backend used in osmo_io. More...
 

Functions

void osmo_iofd_init (void)
 initialize osmo_io for the current thread More...
 
static __attribute__ ((constructor(103)))
 
struct iofd_msghdriofd_msghdr_alloc (struct osmo_io_fd *iofd, enum iofd_msg_action action, struct msgb *msg, size_t cmsg_size)
 Allocate the msghdr. More...
 
void iofd_msghdr_free (struct iofd_msghdr *msghdr)
 Free the msghdr. More...
 
struct msgbiofd_msgb_alloc (struct osmo_io_fd *iofd)
 convenience wrapper to call msgb_alloc with parameters from osmo_io_fd More...
 
struct msgbiofd_msgb_pending (struct osmo_io_fd *iofd)
 return the pending msgb in iofd or NULL if there is none More...
 
struct msgbiofd_msgb_pending_or_alloc (struct osmo_io_fd *iofd)
 Return the pending msgb or allocate and return a new one. More...
 
int iofd_txqueue_enqueue (struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr)
 Enqueue a message to be sent. More...
 
void iofd_txqueue_enqueue_front (struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr)
 Enqueue a message at the front. More...
 
struct iofd_msghdriofd_txqueue_dequeue (struct osmo_io_fd *iofd)
 Dequeue a message from the front. More...
 
static enum iofd_seg_act iofd_handle_segmentation (struct osmo_io_fd *iofd, struct msgb *msg, struct msgb **pending_out)
 Handle segmentation of the msg. More...
 
void iofd_handle_segmented_read (struct osmo_io_fd *iofd, struct msgb *msg, int rc)
 Restore message boundaries on read() and pass individual messages to the read callback. More...
 
void iofd_handle_recv (struct osmo_io_fd *iofd, struct msgb *msg, int rc, struct iofd_msghdr *hdr)
 completion handler: Called by osmo_io backend after a given I/O operation has completed More...
 
void iofd_handle_send_completion (struct osmo_io_fd *iofd, int rc, struct iofd_msghdr *msghdr)
 completion handler: Calld by osmo_io backend after a given I/O operation has completed 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...
 
static int check_mode_callback_compat (enum osmo_io_fd_mode mode, const struct osmo_io_ops *ops)
 
struct osmo_io_fdosmo_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...
 
void osmo_iofd_free (struct osmo_io_fd *iofd)
 Free the iofd. More...
 
int osmo_iofd_close (struct osmo_io_fd *iofd)
 Close the iofd. 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 max_length)
 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...
 
void osmo_iofd_notify_connected (struct osmo_io_fd *iofd)
 Notify the user if/when the socket is connected. More...
 

Variables

const struct value_string osmo_io_backend_names []
 
const struct value_string osmo_iofd_mode_names []
 
static enum osmo_io_backend g_io_backend
 
struct iofd_backend_ops osmo_iofd_ops
 

Detailed Description

New osmocom async I/O API.

(C) 2022-2024 by Harald Welte lafor.nosp@m.ge@o.nosp@m.smoco.nosp@m.m.or.nosp@m.g (C) 2022-2024 by sysmocom - s.f.m.c. GmbH info@.nosp@m.sysm.nosp@m.ocom..nosp@m.de Author: Daniel Willmann dwill.nosp@m.mann.nosp@m.@sysm.nosp@m.ocom.nosp@m..de

All Rights Reserved.

SPDX-License-Identifier: GPL-2.0+

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Macro Definition Documentation

◆ OSMO_IO_BACKEND_ENV

#define OSMO_IO_BACKEND_ENV   "LIBOSMO_IO_BACKEND"

This environment variable can be set to manually set the backend used in osmo_io.

Function Documentation

◆ __attribute__()

◆ check_mode_callback_compat()

◆ iofd_handle_recv()

void iofd_handle_recv ( struct osmo_io_fd iofd,
struct msgb msg,
int  rc,
struct iofd_msghdr hdr 
)

completion handler: Called by osmo_io backend after a given I/O operation has completed

Parameters
[in]iofdI/O file-descriptor on which I/O has completed
[in]msgmessage buffer containing data related to completed I/O
[in]rcresult code with read size or error (-errno)
[in]hdrserialized msghdr containing state of completed I/O

References osmo_io_fd::ctx, hdr, osmo_io_fd::io_ops, iofd_handle_segmented_read(), osmo_io_fd::mode, msg, osmo_io_fd::msgb_alloc, OSMO_ASSERT, OSMO_IO_FD_MODE_READ_WRITE, OSMO_IO_FD_MODE_RECVFROM_SENDTO, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, osmo_io_ops::recvfrom_cb, and osmo_io_ops::recvmsg_cb.

Referenced by iofd_poll_ofd_cb_recvmsg_sendmsg().

◆ iofd_handle_segmentation()

static enum iofd_seg_act iofd_handle_segmentation ( struct osmo_io_fd iofd,
struct msgb msg,
struct msgb **  pending_out 
)
static

Handle segmentation of the msg.

If this function returns *_HANDLE_ONE or MORE then the data in msg will contain one complete message. If there are bytes left over, *pending_out will point to a msgb with the remaining data.

References data, osmo_io_fd::io_ops, iofd_msgb_alloc(), IOFD_SEG_ACT_DEFER, IOFD_SEG_ACT_HANDLE_MORE, IOFD_SEG_ACT_HANDLE_ONE, LOGL_ERROR, LOGPIO, msg, msgb_data(), msgb_free(), msgb_length(), msgb_put(), and osmo_io_ops::segmentation_cb.

Referenced by iofd_handle_segmented_read().

◆ iofd_handle_segmented_read()

void iofd_handle_segmented_read ( struct osmo_io_fd iofd,
struct msgb msg,
int  rc 
)

Restore message boundaries on read() and pass individual messages to the read callback.

References osmo_io_fd::io_ops, iofd_handle_segmentation(), IOFD_SEG_ACT_DEFER, IOFD_SEG_ACT_HANDLE_MORE, osmo_io_fd::mode, msg, OSMO_ASSERT, OSMO_IO_FD_MODE_READ_WRITE, osmo_io_fd::pending, osmo_io_ops::read_cb, and res.

Referenced by iofd_handle_recv().

◆ iofd_handle_send_completion()

void iofd_handle_send_completion ( struct osmo_io_fd iofd,
int  rc,
struct iofd_msghdr msghdr 
)

completion handler: Calld by osmo_io backend after a given I/O operation has completed

Parameters
[in]iofdI/O file-descriptor on which I/O has completed
[in]rcreturn value of the I/O operation
[in]msghdrserialized msghdr containing state of completed I/O

References iofd_msghdr::action, osmo_io_fd::io_ops, IOFD_ACT_SENDMSG, IOFD_ACT_SENDTO, IOFD_ACT_WRITE, iofd_msghdr_free(), iofd_txqueue_enqueue_front(), iofd_msghdr::iov, msg, iofd_msghdr::msg, msgb_free(), msgb_length(), msgb_pull(), iofd_msghdr::osa, OSMO_ASSERT, osmo_io_ops::sendmsg_cb, osmo_io_ops::sendto_cb, and osmo_io_ops::write_cb.

Referenced by iofd_poll_ofd_cb_recvmsg_sendmsg().

◆ iofd_msgb_alloc()

struct msgb * iofd_msgb_alloc ( struct osmo_io_fd iofd)

◆ iofd_msgb_pending()

struct msgb * iofd_msgb_pending ( struct osmo_io_fd iofd)

return the pending msgb in iofd or NULL if there is none

References msg, and osmo_io_fd::pending.

Referenced by iofd_msgb_pending_or_alloc().

◆ iofd_msgb_pending_or_alloc()

struct msgb * iofd_msgb_pending_or_alloc ( struct osmo_io_fd iofd)

Return the pending msgb or allocate and return a new one.

References iofd_msgb_alloc(), iofd_msgb_pending(), and msg.

Referenced by iofd_poll_ofd_cb_recvmsg_sendmsg().

◆ iofd_msghdr_alloc()

struct iofd_msghdr * iofd_msghdr_alloc ( struct osmo_io_fd iofd,
enum iofd_msg_action  action,
struct msgb msg,
size_t  cmsg_size 
)

Allocate the msghdr.

Parameters
[in]iofdthe osmo_io file structure
[in]actionthe action this msg(hdr) is for (read, write, ..)
[in]msgthe msg buffer to use. Will allocate a new one if NULL
[in]cmsg_sizesize (in bytes) of iofd_msghdr.cmsg buffer. Can be 0 if cmsg is not used.
Returns
the newly allocated msghdr or NULL in case of error

References iofd_msghdr::action, iofd_msghdr::hdr, iofd_msghdr::iofd, iofd_msgb_alloc(), and iofd_msghdr::msg.

Referenced by osmo_iofd_sendmsg_msgb(), osmo_iofd_sendto_msgb(), and osmo_iofd_write_msgb().

◆ iofd_msghdr_free()

void iofd_msghdr_free ( struct iofd_msghdr msghdr)

Free the msghdr.

Parameters
[in]msghdrthe msghdr to free

Referenced by iofd_handle_send_completion(), osmo_iofd_sendmsg_msgb(), osmo_iofd_sendto_msgb(), osmo_iofd_txqueue_clear(), and osmo_iofd_write_msgb().

◆ iofd_txqueue_dequeue()

struct iofd_msghdr * iofd_txqueue_dequeue ( struct osmo_io_fd iofd)

Dequeue a message from the front.

Parameters
[in]iofdthe file descriptor
Returns
the msghdr from the front of the queue or NULL if the queue is empty

References osmo_io_fd::current_length, list, llist_del(), llist_entry, osmo_io_fd::msg_queue, llist_head::next, OSMO_ASSERT, osmo_iofd_ops, osmo_io_fd::tx_queue, and iofd_backend_ops::write_disable.

Referenced by iofd_poll_ofd_cb_recvmsg_sendmsg(), and osmo_iofd_txqueue_clear().

◆ iofd_txqueue_enqueue()

int iofd_txqueue_enqueue ( struct osmo_io_fd iofd,
struct iofd_msghdr msghdr 
)

Enqueue a message to be sent.

Enqueues the message at the back of the queue provided there is enough space.

Parameters
[in]iofdthe file descriptor
[in]msghdrthe message to enqueue
Returns
0 if the message was enqueued succcessfully, -ENOSPC if the queue already contains the maximum number of messages

References osmo_io_fd::current_length, IOFD_FLAG_CLOSED, IOFD_FLAG_ISSET, iofd_msghdr::list, llist_add_tail(), osmo_io_fd::max_length, osmo_io_fd::msg_queue, osmo_iofd_ops, osmo_io_fd::tx_queue, and iofd_backend_ops::write_enable.

Referenced by osmo_iofd_sendmsg_msgb(), osmo_iofd_sendto_msgb(), and osmo_iofd_write_msgb().

◆ iofd_txqueue_enqueue_front()

void iofd_txqueue_enqueue_front ( struct osmo_io_fd iofd,
struct iofd_msghdr msghdr 
)

Enqueue a message at the front.

Used to enqueue a msgb from a partial send again. This function will always enqueue the message, even if the maximum number of messages is reached.

Parameters
[in]iofdthe file descriptor
[in]msghdrthe message to enqueue

References osmo_io_fd::current_length, IOFD_FLAG_CLOSED, IOFD_FLAG_ISSET, iofd_msghdr::list, llist_add(), osmo_io_fd::msg_queue, osmo_iofd_ops, osmo_io_fd::tx_queue, and iofd_backend_ops::write_enable.

Referenced by iofd_handle_send_completion().

◆ osmo_iofd_close()

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()

Parameters
[in]iofdthe 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().

◆ 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.

Parameters
[in]iofdthe file descriptor

References iofd_msghdr::iofd, IOFD_FLAG_IN_CALLBACK, IOFD_FLAG_ISSET, IOFD_FLAG_SET, IOFD_FLAG_TO_FREE, and osmo_iofd_close().

◆ osmo_iofd_get_data()

void * osmo_iofd_get_data ( const struct osmo_io_fd iofd)

Get the associated user-data from an iofd.

Parameters
[in]iofdthe file descriptor
Returns
the data that was previously set with osmo_iofd_setup()

References osmo_io_fd::data, and iofd_msghdr::iofd.

◆ osmo_iofd_get_fd()

int osmo_iofd_get_fd ( const struct osmo_io_fd iofd)

Get the underlying file descriptor from an iofd.

Parameters
[in]iofdthe file descriptor
Returns
the underlying file descriptor number

References osmo_io_fd::fd, and iofd_msghdr::iofd.

◆ osmo_iofd_get_ioops()

void osmo_iofd_get_ioops ( struct osmo_io_fd iofd,
struct osmo_io_ops ioops 
)

Get the osmo_io_ops for an iofd.

Parameters
[in]iofdTarget iofd file descriptor
[in]ioopscaller-allocated osmo_io_ops structure to be filled

References osmo_io_fd::io_ops, and iofd_msghdr::iofd.

◆ osmo_iofd_get_name()

const char * osmo_iofd_get_name ( const struct osmo_io_fd iofd)

Get the name of the file descriptor.

Parameters
[in]iofdthe file descriptor
Returns
the name of the iofd as given in osmo_iofd_setup()

References iofd_msghdr::iofd, and osmo_io_fd::name.

◆ osmo_iofd_get_priv_nr()

unsigned int osmo_iofd_get_priv_nr ( const struct osmo_io_fd iofd)

Get the private number from an iofd.

Parameters
[in]iofdthe file descriptor
Returns
the private number that was previously set with osmo_iofd_set_priv_nr()

References iofd_msghdr::iofd, and osmo_io_fd::priv_nr.

◆ osmo_iofd_init()

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__().

◆ osmo_iofd_notify_connected()

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.

Parameters
[in]iofdthe 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.

◆ osmo_iofd_register()

int osmo_iofd_register ( struct osmo_io_fd iofd,
int  fd 
)

Register the fd with the underlying backend.

Parameters
[in]iofdthe iofd file descriptor
[in]fdthe system fd number that will be registeres. If negative will use the one already set.
Returns
zero on success, a negative value on error

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.

◆ osmo_iofd_sendmsg_msgb()

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.

Parameters
[in]iofdfile descriptor to write to
[in]msgmessage buffer to send; is used to fill msgh->iov[]
[in]sendmsg_flagsFlags to pass to the send call
[in]msgh'struct msghdr' for name/control/flags. iov must be empty!
Returns
0 in case of success; a negative value in case of error

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.

◆ osmo_iofd_sendto_msgb()

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.

Parameters
[in]iofdfile descriptor to write to
[in]msgmessage buffer to send
[in]sendto_flagsFlags to pass to the send call
[in]destdestination address to send the message to
Returns
0 in case of success; a negative value in case of error

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.

◆ osmo_iofd_set_alloc_info()

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.

Parameters
[in]iofdthe file descriptor
[in]sizethe size of the msgb when receiving data
[in]headroomthe 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.

◆ osmo_iofd_set_cmsg_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.

◆ osmo_iofd_set_data()

void osmo_iofd_set_data ( struct osmo_io_fd iofd,
void *  data 
)

Set the associated user-data from an iofd.

Parameters
[in]iofdthe file descriptor
[in]datathe data to set

References data, osmo_io_fd::data, and iofd_msghdr::iofd.

◆ osmo_iofd_set_ioops()

◆ osmo_iofd_set_name()

void osmo_iofd_set_name ( struct osmo_io_fd iofd,
const char *  name 
)

Set the name of the file descriptor.

Parameters
[in]iofdthe file descriptor
[in]namethe name to set on the file descriptor

References iofd_msghdr::iofd, name, osmo_io_fd::name, and osmo_talloc_replace_string().

◆ osmo_iofd_set_priv_nr()

void osmo_iofd_set_priv_nr ( struct osmo_io_fd iofd,
unsigned int  priv_nr 
)

Set the private number from an iofd.

Parameters
[in]iofdthe file descriptor
[in]priv_nrthe private number to set

References iofd_msghdr::iofd, and osmo_io_fd::priv_nr.

◆ osmo_iofd_set_txqueue_max_length()

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.

Parameters
[in]iofdthe file descriptor
[in]sizethe maximum size of the transmit queue

References iofd_msghdr::iofd, osmo_io_fd::max_length, and osmo_io_fd::tx_queue.

◆ osmo_iofd_setup()

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.

Parameters
[in]ctxthe parent context from which to allocate
[in]fdthe underlying system file descriptor
[in]namethe name of the iofd
[in]modethe mode of the iofd, whether it should use read()/write(), sendto()/recvfrom()
[in]ioopsstructure with read/write/send/recv callbacks
[in]datauser data pointer accessible by the ioops callbacks
Returns
The newly allocated osmo_io_fd struct or NULL on failure

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.

◆ osmo_iofd_txqueue_clear()

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

Parameters
[in]iofdthe file descriptor

References iofd_msghdr::hdr, iofd_msghdr::iofd, iofd_msghdr_free(), iofd_txqueue_dequeue(), and msgb_free().

Referenced by osmo_iofd_close().

◆ osmo_iofd_txqueue_len()

unsigned int osmo_iofd_txqueue_len ( struct osmo_io_fd iofd)

Get the number of messages in the tx queue.

Parameters
[in]iofdthe file descriptor

References osmo_io_fd::current_length, and osmo_io_fd::tx_queue.

Referenced by iofd_poll_ofd_cb_recvmsg_sendmsg().

◆ osmo_iofd_unregister()

int osmo_iofd_unregister ( struct osmo_io_fd iofd)

Unregister the fd from the underlying backend.

Parameters
[in]iofdthe file descriptor
Returns
zero on success, a negative value on error

References osmo_iofd_ops, and iofd_backend_ops::unregister_fd.

◆ osmo_iofd_write_msgb()

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.

Parameters
[in]iofdfile descriptor to write to
[in]msgmessage buffer to write
Returns
0 in case of success; a negative value in case of error

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.

Variable Documentation

◆ g_io_backend

enum osmo_io_backend g_io_backend
static

Referenced by __attribute__(), and osmo_iofd_init().

◆ osmo_io_backend_names

const struct value_string osmo_io_backend_names[]
Initial value:
= {
{ OSMO_IO_BACKEND_POLL, "poll" },
{ OSMO_IO_BACKEND_IO_URING, "io_uring" },
{ 0, NULL }
}
@ OSMO_IO_BACKEND_POLL
Definition: osmo_io.h:31
@ OSMO_IO_BACKEND_IO_URING
Definition: osmo_io.h:32

Referenced by osmo_io_backend_name().

◆ osmo_iofd_mode_names

const struct value_string osmo_iofd_mode_names[]
Initial value:
= {
{ OSMO_IO_FD_MODE_READ_WRITE, "read/write" },
{ OSMO_IO_FD_MODE_RECVFROM_SENDTO, "recvfrom/sendto" },
{ OSMO_IO_FD_MODE_RECVMSG_SENDMSG, "recvmsg/sendmsg" },
{ 0, NULL }
}
@ OSMO_IO_FD_MODE_RECVFROM_SENDTO
use recvfrom() / sendto() calls
Definition: osmo_io.h:25
@ OSMO_IO_FD_MODE_RECVMSG_SENDMSG
emulate recvmsg() / sendmsg()
Definition: osmo_io.h:27
@ OSMO_IO_FD_MODE_READ_WRITE
use read() / write() calls
Definition: osmo_io.h:23

Referenced by osmo_iofd_mode_name().

◆ osmo_iofd_ops