libosmocore 1.9.0.186-fab9.202403182026
Osmocom core library
|
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_msghdr * | iofd_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 msgb * | iofd_msgb_alloc (struct osmo_io_fd *iofd) |
convenience wrapper to call msgb_alloc with parameters from osmo_io_fd More... | |
struct msgb * | iofd_msgb_pending (struct osmo_io_fd *iofd) |
return the pending msgb in iofd or NULL if there is none More... | |
struct msgb * | iofd_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_msghdr * | iofd_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_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... | |
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 |
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.
#define OSMO_IO_BACKEND_ENV "LIBOSMO_IO_BACKEND" |
This environment variable can be set to manually set the backend used in osmo_io.
|
static |
References iofd_backend_ops::close, g_io_backend, iofd_poll_ops, iofd_backend_ops::notify_connected, OSMO_ASSERT, OSMO_IO_BACKEND_DEFAULT, OSMO_IO_BACKEND_ENV, OSMO_IO_BACKEND_IO_URING, OSMO_IO_BACKEND_POLL, osmo_iofd_init(), osmo_iofd_ops, iofd_backend_ops::read_disable, iofd_backend_ops::read_enable, iofd_backend_ops::register_fd, iofd_backend_ops::unregister_fd, iofd_backend_ops::write_disable, and iofd_backend_ops::write_enable.
|
static |
References mode, OSMO_IO_FD_MODE_READ_WRITE, OSMO_IO_FD_MODE_RECVFROM_SENDTO, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, osmo_io_ops::read_cb, osmo_io_ops::recvfrom_cb, osmo_io_ops::recvmsg_cb, osmo_io_ops::sendmsg_cb, osmo_io_ops::sendto_cb, and osmo_io_ops::write_cb.
Referenced by osmo_iofd_set_ioops(), and osmo_iofd_setup().
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
[in] | iofd | I/O file-descriptor on which I/O has completed |
[in] | msg | message buffer containing data related to completed I/O |
[in] | rc | result code with read size or error (-errno) |
[in] | hdr | serialized 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().
|
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().
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().
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
[in] | iofd | I/O file-descriptor on which I/O has completed |
[in] | rc | return value of the I/O operation |
[in] | msghdr | serialized 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().
struct msgb * iofd_msgb_alloc | ( | struct osmo_io_fd * | iofd | ) |
convenience wrapper to call msgb_alloc with parameters from osmo_io_fd
References osmo_io_fd::headroom, osmo_io_fd::msgb_alloc, msgb_alloc_headroom_c(), OSMO_ASSERT, and osmo_io_fd::size.
Referenced by iofd_handle_segmentation(), iofd_msgb_pending_or_alloc(), and iofd_msghdr_alloc().
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().
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().
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.
[in] | iofd | the osmo_io file structure |
[in] | action | the action this msg(hdr) is for (read, write, ..) |
[in] | msg | the msg buffer to use. Will allocate a new one if NULL |
[in] | cmsg_size | size (in bytes) of iofd_msghdr.cmsg buffer. Can be 0 if cmsg is not used. |
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().
void iofd_msghdr_free | ( | struct iofd_msghdr * | msghdr | ) |
Free the msghdr.
[in] | msghdr | the 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().
struct iofd_msghdr * iofd_txqueue_dequeue | ( | struct osmo_io_fd * | iofd | ) |
Dequeue a message from the front.
[in] | iofd | the file descriptor |
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().
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.
[in] | iofd | the file descriptor |
[in] | msghdr | the message to enqueue |
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().
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.
[in] | iofd | the file descriptor |
[in] | msghdr | the 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().
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__().
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.
|
static |
Referenced by __attribute__(), and osmo_iofd_init().
const struct value_string osmo_io_backend_names[] |
Referenced by osmo_io_backend_name().
const struct value_string osmo_iofd_mode_names[] |
Referenced by osmo_iofd_mode_name().
struct iofd_backend_ops osmo_iofd_ops |