libosmocore UNKNOWN
Osmocom core library
Loading...
Searching...
No Matches
osmo_io_internal.h
Go to the documentation of this file.
1
2
3#pragma once
4
5#include "../config.h"
6
7#include <unistd.h>
8#include <stdbool.h>
9
12#include <osmocom/core/msgb.h>
13#include <osmocom/core/select.h>
14#include <osmocom/core/socket.h>
15
16#define OSMO_IO_DEFAULT_MSGB_SIZE 1024
17#define OSMO_IO_DEFAULT_MSGB_HEADROOM 128
18
19extern const struct iofd_backend_ops iofd_poll_ops;
20#define OSMO_IO_BACKEND_DEFAULT "POLL"
21
22#if defined(HAVE_URING)
23extern const struct iofd_backend_ops iofd_uring_ops;
24void osmo_iofd_uring_constructor(void);
25void osmo_iofd_uring_init(void);
26#endif
27
29 int (*setup)(struct osmo_io_fd *iofd);
30 int (*register_fd)(struct osmo_io_fd *iofd);
31 int (*unregister_fd)(struct osmo_io_fd *iofd);
32 int (*close)(struct osmo_io_fd *iofd);
33 void (*write_enable)(struct osmo_io_fd *iofd);
34 void (*write_disable)(struct osmo_io_fd *iofd);
35 void (*read_enable)(struct osmo_io_fd *iofd);
36 void (*read_disable)(struct osmo_io_fd *iofd);
37 void (*notify_connected)(struct osmo_io_fd *iofd);
38};
39
40#define IOFD_FLAG_CLOSED (1<<0)
41#define IOFD_FLAG_IN_CALLBACK (1<<1)
42#define IOFD_FLAG_TO_FREE (1<<2)
43#define IOFD_FLAG_NOTIFY_CONNECTED (1<<3)
44#define IOFD_FLAG_FD_REGISTERED (1<<4)
45
46#define IOFD_FLAG_SET(iofd, flag) \
47 (iofd)->flags |= (flag)
48
49#define IOFD_FLAG_UNSET(iofd, flag) \
50 (iofd)->flags &= ~(flag)
51
52#define IOFD_FLAG_ISSET(iofd, flag) ((iofd)->flags & (flag))
53
54#define IOFD_MSGHDR_MAX_READ_SQES 32
55
56struct osmo_io_fd {
60 int fd;
63
65 uint32_t flags;
66
68 char *name;
69
73 struct msgb *pending;
74
76 void *data;
78 unsigned int priv_nr;
79
81 size_t cmsg_size;
82
85
88
89 struct {
91 const void *ctx;
93 unsigned int size;
95 unsigned int headroom;
97
98 struct {
100 unsigned int max_length;
102 unsigned int current_length;
104 struct llist_head msg_queue;
106
107 union {
108 struct {
109 struct osmo_fd ofd;
110 } poll;
111 struct {
112 struct {
114 bool enabled;
116 uint8_t num_sqes;
120 struct io_uring *ring;
122 uint8_t sqes_submitted;
123 } read;
124 struct {
126 bool enabled;
128 void *msghdr;
130 struct io_uring *ring;
131 } write;
132 /* TODO: index into array of registered fd's? */
133 /* osmo_fd for non-blocking connect handling */
134 struct osmo_fd connect_ofd;
135 } uring;
136 } u;
137};
138
147
148#define IOFD_MSGHDR_IO_BUFFERS 8
149
156 struct msghdr hdr;
163 int flags;
164
166 uint8_t io_len;
171
174
179 char _Alignas(struct cmsghdr) cmsg[0];
180};
181
187
188struct iofd_msghdr *iofd_msghdr_alloc(struct osmo_io_fd *iofd, enum iofd_msg_action action, struct msgb *msg, size_t cmsg_size);
189void iofd_msghdr_free(struct iofd_msghdr *msghdr);
190
191struct msgb *iofd_msgb_alloc2(struct osmo_io_fd *iofd, size_t size);
192struct msgb *iofd_msgb_alloc(struct osmo_io_fd *iofd);
193
194void iofd_handle_recv(struct osmo_io_fd *iofd, struct msgb *msg, int rc, struct iofd_msghdr *msghdr);
195void iofd_handle_send_completion(struct osmo_io_fd *iofd, int rc, struct iofd_msghdr *msghdr);
196
197int iofd_txqueue_enqueue(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr);
198void iofd_txqueue_enqueue_front(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr);
struct msgb * msgb_alloc(uint16_t size, const char *name)
Allocate a new message buffer from tall_msgb_ctx.
Definition msgb.c:109
void iofd_txqueue_enqueue_front(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr)
Enqueue a message at the front.
Definition osmo_io.c:238
osmo_io_fd_mode
The mode of an osmo_io_fd determines if read/write, recvfrom/sendmsg or recvmsg/sendmsg semantics are...
Definition osmo_io.h:66
void iofd_msghdr_free(struct iofd_msghdr *msghdr)
Free the msghdr.
Definition osmo_io.c:184
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 compl...
Definition osmo_io.c:537
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.
Definition osmo_io.c:142
struct msgb * iofd_msgb_alloc2(struct osmo_io_fd *iofd, size_t size)
convenience wrapper to call msgb_alloc with parameters from osmo_io_fd (of given size)
Definition osmo_io.c:192
struct msgb * iofd_msgb_alloc(struct osmo_io_fd *iofd)
convenience wrapper to call msgb_alloc with parameters from osmo_io_fd
Definition osmo_io.c:201
int iofd_txqueue_enqueue(struct osmo_io_fd *iofd, struct iofd_msghdr *msghdr)
Enqueue a message to be sent.
Definition osmo_io.c:214
struct iofd_msghdr * iofd_txqueue_dequeue(struct osmo_io_fd *iofd)
Dequeue a message from the front.
Definition osmo_io.c:252
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 compl...
Definition osmo_io.c:492
uint8_t msg[0]
Simple doubly linked list implementation.
io(_uring) abstraction osmo fd compatibility
#define IOFD_MSGHDR_MAX_READ_SQES
Definition osmo_io_internal.h:54
#define IOFD_MSGHDR_IO_BUFFERS
Definition osmo_io_internal.h:148
iofd_msg_action
Definition osmo_io_internal.h:139
@ IOFD_ACT_RECVFROM
Definition osmo_io_internal.h:142
@ IOFD_ACT_RECVMSG
Definition osmo_io_internal.h:144
@ IOFD_ACT_SENDTO
Definition osmo_io_internal.h:143
@ IOFD_ACT_READ
Definition osmo_io_internal.h:140
@ IOFD_ACT_WRITE
Definition osmo_io_internal.h:141
@ IOFD_ACT_SENDMSG
Definition osmo_io_internal.h:145
iofd_seg_act
Definition osmo_io_internal.h:182
@ IOFD_SEG_ACT_DEFER
Definition osmo_io_internal.h:185
@ IOFD_SEG_ACT_HANDLE_MORE
Definition osmo_io_internal.h:184
@ IOFD_SEG_ACT_HANDLE_ONE
Definition osmo_io_internal.h:183
const struct iofd_backend_ops iofd_poll_ops
Definition osmo_io_poll.c:261
libmnl integration
Osmocom socket convenience functions.
Definition osmo_io_internal.h:28
void(*) notify_connected(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:37
void(*) write_enable(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:33
void(*) read_enable(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:35
int(*) close(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:32
int(*) setup(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:29
void(*) read_disable(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:36
void(*) write_disable(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:34
int(*) unregister_fd(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:31
int(*) register_fd(struct osmo_io_fd *iofd)
Definition osmo_io_internal.h:30
serialized version of 'struct msghdr' employed by sendmsg/recvmsg
Definition osmo_io_internal.h:151
struct osmo_io_fd * iofd
I/O file descriptor on which we perform this I/O operation.
Definition osmo_io_internal.h:170
struct llist_head list
entry into osmo_io_fd.tx_queue.msg_queue
Definition osmo_io_internal.h:153
int flags
flags we pass as argument to sendmsg / recvmsg
Definition osmo_io_internal.h:163
char _Alignas(struct cmsghdr) cmsg[0]
control message buffer for passing sctp_sndrcvinfo along.
enum iofd_msg_action action
Definition osmo_io_internal.h:154
uint8_t io_len
current number of message-buffers that are stored
Definition osmo_io_internal.h:166
struct msghdr hdr
the 'struct msghdr' we are wrapping/ecapsulating here
Definition osmo_io_internal.h:156
struct osmo_sockaddr osa
socket address of the remote peer
Definition osmo_io_internal.h:158
struct msgb * msg[IOFD_MSGHDR_IO_BUFFERS]
message-buffer containing data for this I/O operation
Definition osmo_io_internal.h:168
bool in_cancel_queue
msghdr is in the cancel_queue list
Definition osmo_io_internal.h:173
struct iovec iov[IOFD_MSGHDR_IO_BUFFERS]
io-vector we need to pass as argument to sendmsg/recvmsg; is set up to point into msg below
Definition osmo_io_internal.h:161
(double) linked list header structure
Definition linuxlist.h:46
Osmocom message buffer.
Definition msgb.h:31
Structure representing a file dsecriptor.
Definition select.h:31
const void * ctx
talloc context from which to allocate msgb when reading
unsigned int size
size of msgb to allocate (excluding headroom)
unsigned int headroom
headroom to allocate when allocating msgb's
struct llist_head msg_queue
actual linked list implementing the transmit queue
unsigned int max_length
maximum length of write queue
unsigned int current_length
current length of write queue
bool enabled
read is enabled, due to registration of callback function
void * msghdr[IOFD_MSGHDR_MAX_READ_SQES]
array of simultaneously submitted read SQEs
struct io_uring * ring
ring the read SQEs have been submitted to
uint8_t sqes_submitted
current number of simultaneously submitted read SQEs
uint8_t num_sqes
requested number of simultaniously submitted read SQEs
bool enabled
write is enabled, due to pending msghdr in tx_queue
struct io_uring * ring
ring the write SQE has been submitted to
struct osmo_io_fd::@040257067356231006065175370111377221044300253311::@014163026161032226054037307362112337171306222277::@315111126276164227176065361173262256176344366071 write
struct osmo_io_fd::@040257067356231006065175370111377221044300253311::@014163026161032226054037307362112337171306222277::@332175356333221345071101235261106345261272162141 read
Definition osmo_io_internal.h:56
uint32_t flags
flags to guard closing/freeing of iofd
Definition osmo_io_internal.h:65
struct msgb * pending
Pending msgb to keep partial data during segmentation.
Definition osmo_io_internal.h:73
enum osmo_io_fd_mode mode
type of read/write mode to use
Definition osmo_io_internal.h:62
char * name
human-readable name to associte with fd
Definition osmo_io_internal.h:68
struct llist_head list
linked list for internal management
Definition osmo_io_internal.h:58
size_t cmsg_size
size of iofd_msghdr.cmsg[] when allocated in recvmsg path
Definition osmo_io_internal.h:81
uint8_t io_write_buffers
maximum number of message-buffers per write operation
Definition osmo_io_internal.h:87
int fd
actual operating-system level file decriptor
Definition osmo_io_internal.h:60
uint8_t io_read_buffers
maximum number of message-buffers per read operation
Definition osmo_io_internal.h:84
struct osmo_io_ops io_ops
send/recv (msg) callback functions
Definition osmo_io_internal.h:71
void * data
data pointer passed through to call-back function
Definition osmo_io_internal.h:76
unsigned int priv_nr
private number, extending data
Definition osmo_io_internal.h:78
struct osmo_io_fd::@213032166116346075373040302302243174211211232213 tx_queue
union osmo_io_fd::@040257067356231006065175370111377221044300253311 u
I/O operations (call-back functions) related to an osmo_io_fd.
Definition osmo_io.h:105
Definition socket.h:33
struct osmo_io_fd::@040257067356231006065175370111377221044300253311::@014163026161032226054037307362112337171306222277 uring
struct osmo_io_fd::@040257067356231006065175370111377221044300253311::@177346222244255162144040225120277250127071210262 poll