libosmocore 1.9.0.186-fab9.202403182026
Osmocom core library
osmo_io_internal.h File Reference
#include <unistd.h>
#include <stdbool.h>
#include <netinet/sctp.h>
#include <osmocom/core/osmo_io.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/select.h>
#include <osmocom/core/socket.h>
#include "../config.h"

Go to the source code of this file.

Data Structures

struct  iofd_backend_ops
 
struct  osmo_io_fd
 
struct  iofd_msghdr
 serialized version of 'struct msghdr' employed by sendmsg/recvmsg More...
 

Macros

#define OSMO_IO_DEFAULT_MSGB_SIZE   1024
 
#define OSMO_IO_DEFAULT_MSGB_HEADROOM   128
 
#define OSMO_IO_BACKEND_DEFAULT   "POLL"
 
#define IOFD_FLAG_CLOSED   (1<<0)
 
#define IOFD_FLAG_IN_CALLBACK   (1<<1)
 
#define IOFD_FLAG_TO_FREE   (1<<2)
 
#define IOFD_FLAG_NOTIFY_CONNECTED   (1<<3)
 
#define IOFD_FLAG_FD_REGISTERED   (1<<4)
 
#define IOFD_FLAG_SET(iofd, flag)    (iofd)->flags |= (flag)
 
#define IOFD_FLAG_UNSET(iofd, flag)    (iofd)->flags &= ~(flag)
 
#define IOFD_FLAG_ISSET(iofd, flag)   ((iofd)->flags & (flag))
 

Enumerations

enum  iofd_msg_action {
  IOFD_ACT_READ ,
  IOFD_ACT_WRITE ,
  IOFD_ACT_RECVFROM ,
  IOFD_ACT_SENDTO ,
  IOFD_ACT_RECVMSG ,
  IOFD_ACT_SENDMSG
}
 
enum  iofd_seg_act {
  IOFD_SEG_ACT_HANDLE_ONE ,
  IOFD_SEG_ACT_HANDLE_MORE ,
  IOFD_SEG_ACT_DEFER
}
 

Functions

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...
 
void iofd_handle_recv (struct osmo_io_fd *iofd, struct msgb *msg, int rc, struct iofd_msghdr *msghdr)
 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...
 
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...
 
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...
 

Variables

const struct iofd_backend_ops iofd_poll_ops
 

Macro Definition Documentation

◆ IOFD_FLAG_CLOSED

#define IOFD_FLAG_CLOSED   (1<<0)

◆ IOFD_FLAG_FD_REGISTERED

#define IOFD_FLAG_FD_REGISTERED   (1<<4)

◆ IOFD_FLAG_IN_CALLBACK

#define IOFD_FLAG_IN_CALLBACK   (1<<1)

◆ IOFD_FLAG_ISSET

#define IOFD_FLAG_ISSET (   iofd,
  flag 
)    ((iofd)->flags & (flag))

◆ IOFD_FLAG_NOTIFY_CONNECTED

#define IOFD_FLAG_NOTIFY_CONNECTED   (1<<3)

◆ IOFD_FLAG_SET

#define IOFD_FLAG_SET (   iofd,
  flag 
)     (iofd)->flags |= (flag)

◆ IOFD_FLAG_TO_FREE

#define IOFD_FLAG_TO_FREE   (1<<2)

◆ IOFD_FLAG_UNSET

#define IOFD_FLAG_UNSET (   iofd,
  flag 
)     (iofd)->flags &= ~(flag)

◆ OSMO_IO_BACKEND_DEFAULT

#define OSMO_IO_BACKEND_DEFAULT   "POLL"

◆ OSMO_IO_DEFAULT_MSGB_HEADROOM

#define OSMO_IO_DEFAULT_MSGB_HEADROOM   128

◆ OSMO_IO_DEFAULT_MSGB_SIZE

#define OSMO_IO_DEFAULT_MSGB_SIZE   1024

Enumeration Type Documentation

◆ iofd_msg_action

Enumerator
IOFD_ACT_READ 
IOFD_ACT_WRITE 
IOFD_ACT_RECVFROM 
IOFD_ACT_SENDTO 
IOFD_ACT_RECVMSG 
IOFD_ACT_SENDMSG 

◆ iofd_seg_act

Enumerator
IOFD_SEG_ACT_HANDLE_ONE 
IOFD_SEG_ACT_HANDLE_MORE 
IOFD_SEG_ACT_DEFER 

Function Documentation

◆ 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_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().

Variable Documentation

◆ iofd_poll_ops

const struct iofd_backend_ops iofd_poll_ops
extern