libosmocore 1.9.0.107-1cfc.202312262026
Osmocom core library
osmo_io.h
Go to the documentation of this file.
1
5#pragma once
6
9#include <osmocom/core/msgb.h>
10#include <osmocom/core/socket.h>
11#include <osmocom/core/utils.h>
12
13
14#define LOGPIO(iofd, level, fmt, args...) \
15 LOGP(DLIO, level, "iofd(%s)" fmt, iofd->name, ## args)
16
17struct osmo_io_fd;
18
26};
27
31};
32
33extern const struct value_string osmo_io_backend_names[];
34static inline const char *osmo_io_backend_name(enum osmo_io_backend val)
36
38 union {
39 /* mode OSMO_IO_FD_MODE_READ_WRITE: */
40 struct {
42 void (*read_cb)(struct osmo_io_fd *iofd, int res, struct msgb *msg);
44 void (*write_cb)(struct osmo_io_fd *iofd, int res,
45 struct msgb *msg);
55 int (*segmentation_cb)(struct msgb *msg);
56 };
57
58 /* mode OSMO_IO_FD_MODE_RECVFROM_SENDTO: */
59 struct {
61 void (*recvfrom_cb)(struct osmo_io_fd *iofd, int res,
62 struct msgb *msg,
63 const struct osmo_sockaddr *saddr);
65 void (*sendto_cb)(struct osmo_io_fd *iofd, int res,
66 struct msgb *msg,
67 const struct osmo_sockaddr *daddr);
68 };
69 };
70};
71
72void osmo_iofd_init(void);
73
74struct osmo_io_fd *osmo_iofd_setup(const void *ctx, int fd, const char *name,
75 enum osmo_io_fd_mode mode, const struct osmo_io_ops *ioops, void *data);
76int osmo_iofd_register(struct osmo_io_fd *iofd, int fd);
78unsigned int osmo_iofd_txqueue_len(struct osmo_io_fd *iofd);
80int osmo_iofd_close(struct osmo_io_fd *iofd);
81void osmo_iofd_free(struct osmo_io_fd *iofd);
82
84
85int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg);
86int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, int sendto_flags,
87 const struct osmo_sockaddr *dest);
88
89void osmo_iofd_set_alloc_info(struct osmo_io_fd *iofd, unsigned int size, unsigned int headroom);
90void osmo_iofd_set_txqueue_max_length(struct osmo_io_fd *iofd, unsigned int size);
91void *osmo_iofd_get_data(const struct osmo_io_fd *iofd);
92void osmo_iofd_set_data(struct osmo_io_fd *iofd, void *data);
93
94unsigned int osmo_iofd_get_priv_nr(const struct osmo_io_fd *iofd);
95void osmo_iofd_set_priv_nr(struct osmo_io_fd *iofd, unsigned int priv_nr);
96
97int osmo_iofd_get_fd(const struct osmo_io_fd *iofd);
98const char *osmo_iofd_get_name(const struct osmo_io_fd *iofd);
99void osmo_iofd_set_name(struct osmo_io_fd *iofd, const char *name);
100
101void osmo_iofd_set_ioops(struct osmo_io_fd *iofd, const struct osmo_io_ops *ioops);
const char * name
uint8_t res[16]
uint8_t data[0]
const char * get_value_string(const struct value_string *vs, uint32_t val)
get human-readable string for given value
Definition: utils.c:54
uint8_t msg[0]
Simple doubly linked list implementation.
void osmo_iofd_set_data(struct osmo_io_fd *iofd, void *data)
int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg)
osmo_io_fd_mode
Definition: osmo_io.h:19
@ OSMO_IO_FD_MODE_RECVFROM_SENDTO
use recvfrom() / sendto() calls
Definition: osmo_io.h:23
@ OSMO_IO_FD_MODE_SCTP_RECVMSG_SEND
emulate sctp_recvmsg() and sctp_send()
Definition: osmo_io.h:25
@ OSMO_IO_FD_MODE_READ_WRITE
use read() / write() calls
Definition: osmo_io.h:21
void osmo_iofd_set_txqueue_max_length(struct osmo_io_fd *iofd, unsigned int size)
int osmo_iofd_unregister(struct osmo_io_fd *iofd)
static const char * osmo_io_backend_name(enum osmo_io_backend val)
Definition: osmo_io.h:34
void osmo_iofd_notify_connected(struct osmo_io_fd *iofd)
void osmo_iofd_set_priv_nr(struct osmo_io_fd *iofd, unsigned int priv_nr)
osmo_io_backend
Definition: osmo_io.h:28
@ OSMO_IO_BACKEND_POLL
Definition: osmo_io.h:29
@ OSMO_IO_BACKEND_IO_URING
Definition: osmo_io.h:30
void osmo_iofd_txqueue_clear(struct osmo_io_fd *iofd)
void osmo_iofd_set_name(struct osmo_io_fd *iofd, const char *name)
int osmo_iofd_get_fd(const struct osmo_io_fd *iofd)
void osmo_iofd_free(struct osmo_io_fd *iofd)
void osmo_iofd_set_ioops(struct osmo_io_fd *iofd, const struct osmo_io_ops *ioops)
const struct value_string osmo_io_backend_names[]
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)
int osmo_iofd_register(struct osmo_io_fd *iofd, int fd)
unsigned int osmo_iofd_txqueue_len(struct osmo_io_fd *iofd)
void osmo_iofd_init(void)
const char * osmo_iofd_get_name(const struct osmo_io_fd *iofd)
void osmo_iofd_set_alloc_info(struct osmo_io_fd *iofd, unsigned int size, unsigned int headroom)
void * osmo_iofd_get_data(const struct osmo_io_fd *iofd)
unsigned int osmo_iofd_get_priv_nr(const struct osmo_io_fd *iofd)
int osmo_iofd_close(struct osmo_io_fd *iofd)
int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, int sendto_flags, const struct osmo_sockaddr *dest)
Osmocom socket convenience functions.
Osmocom message buffer.
Definition: msgb.h:31
Definition: osmo_io_internal.h:49
enum osmo_io_fd_mode mode
type of read/write mode to use
Definition: osmo_io_internal.h:55
unsigned int headroom
headroom to allocate when allocating msgb's
Definition: osmo_io_internal.h:79
unsigned int size
size of msgb to allocate (excluding headroom)
Definition: osmo_io_internal.h:77
int fd
actual operating-system level file decriptor
Definition: osmo_io_internal.h:53
const void * ctx
talloc context from which to allocate msgb when reading
Definition: osmo_io_internal.h:75
unsigned int priv_nr
private number, extending data
Definition: osmo_io_internal.h:71
Definition: osmo_io.h:37
void(* read_cb)(struct osmo_io_fd *iofd, int res, struct msgb *msg)
call-back function when something was read from fd
Definition: osmo_io.h:42
void(* recvfrom_cb)(struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct osmo_sockaddr *saddr)
call-back function emulating recvfrom
Definition: osmo_io.h:61
void(* write_cb)(struct osmo_io_fd *iofd, int res, struct msgb *msg)
call-back function when write has completed on fd
Definition: osmo_io.h:44
void(* sendto_cb)(struct osmo_io_fd *iofd, int res, struct msgb *msg, const struct osmo_sockaddr *daddr)
call-back function emulating sendto
Definition: osmo_io.h:65
int(* segmentation_cb)(struct msgb *msg)
call-back function to segment the data at message boundaries.
Definition: osmo_io.h:55
Definition: socket.h:38
A mapping between human-readable string and numeric value.
Definition: utils.h:51