libosmocore 1.9.0.196-9975
Osmocom core library
osmo_io.c File Reference
#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: Internal function 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: Internal function called 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)
 Write a message to a file descriptor / 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)
 osmo_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 osmo_io_fd for active I/O. More...
 
int osmo_iofd_unregister (struct osmo_io_fd *iofd)
 Unregister the given osmo_io_fd from osmo_io. More...
 
unsigned int osmo_iofd_txqueue_len (struct osmo_io_fd *iofd)
 Retrieve the number of messages pending in the transmit queue. More...
 
void osmo_iofd_txqueue_clear (struct osmo_io_fd *iofd)
 Clear the transmit queue of the given osmo_io_fd. More...
 
void osmo_iofd_free (struct osmo_io_fd *iofd)
 Free the given osmo_io_fd. More...
 
int osmo_iofd_close (struct osmo_io_fd *iofd)
 Close the given osmo_io_fd. 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)
 Retrieve the associated user-data from an osmo_io_fd. More...
 
void osmo_iofd_set_data (struct osmo_io_fd *iofd, void *data)
 Set the associated user-data from an osmo_io_fd. More...
 
unsigned int osmo_iofd_get_priv_nr (const struct osmo_io_fd *iofd)
 Retrieve the private number from an osmo_io_fd. More...
 
void osmo_iofd_set_priv_nr (struct osmo_io_fd *iofd, unsigned int priv_nr)
 Set the private number of an osmo_io_fd. More...
 
int osmo_iofd_get_fd (const struct osmo_io_fd *iofd)
 Retrieve the underlying file descriptor from an osmo_io_fd. More...
 
const char * osmo_iofd_get_name (const struct osmo_io_fd *iofd)
 Retrieve the human-readable name of the given osmo_io_fd. More...
 
void osmo_iofd_set_name (struct osmo_io_fd *iofd, const char *name)
 Set the human-readable 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 calbacks for an osmo_io_fd. More...
 
void osmo_iofd_get_ioops (struct osmo_io_fd *iofd, struct osmo_io_ops *ioops)
 Retrieve the osmo_io_ops for an iofd. More...
 
void osmo_iofd_notify_connected (struct osmo_io_fd *iofd)
 Request notification of the user if/when a client 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