\doxysection{osmo\+\_\+io\+\_\+internal.\+h}
\label{osmo__io__internal_8h_source}\index{src/core/osmo\_io\_internal.h@{src/core/osmo\_io\_internal.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{4 }
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include "{}../config.h"{}}}
\DoxyCodeLine{6 }
\DoxyCodeLine{7 \textcolor{preprocessor}{\#include <unistd.h>}}
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <stdbool.h>}}
\DoxyCodeLine{9 }
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <osmocom/core/osmo\_io.h>}}
\DoxyCodeLine{11 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{12 \textcolor{preprocessor}{\#include <osmocom/core/msgb.h>}}
\DoxyCodeLine{13 \textcolor{preprocessor}{\#include <osmocom/core/select.h>}}
\DoxyCodeLine{14 \textcolor{preprocessor}{\#include <osmocom/core/socket.h>}}
\DoxyCodeLine{15 }
\DoxyCodeLine{16 \textcolor{preprocessor}{\#define OSMO\_IO\_DEFAULT\_MSGB\_SIZE 1024}}
\DoxyCodeLine{17 \textcolor{preprocessor}{\#define OSMO\_IO\_DEFAULT\_MSGB\_HEADROOM 128}}
\DoxyCodeLine{18 }
\DoxyCodeLine{19 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }iofd\_backend\_ops iofd\_poll\_ops;}
\DoxyCodeLine{20 \textcolor{preprocessor}{\#define OSMO\_IO\_BACKEND\_DEFAULT "{}POLL"{}}}
\DoxyCodeLine{21 }
\DoxyCodeLine{22 \textcolor{preprocessor}{\#if defined(HAVE\_URING)}}
\DoxyCodeLine{23 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }iofd\_backend\_ops iofd\_uring\_ops;}
\DoxyCodeLine{24 \textcolor{keywordtype}{void} osmo\_iofd\_uring\_constructor(\textcolor{keywordtype}{void});}
\DoxyCodeLine{25 \textcolor{keywordtype}{void} osmo\_iofd\_uring\_init(\textcolor{keywordtype}{void});}
\DoxyCodeLine{26 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{27 }
\DoxyCodeLine{28 \textcolor{keyword}{struct }iofd\_backend\_ops \{}
\DoxyCodeLine{29         int (*setup)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{30         int (*register\_fd)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{31         int (*unregister\_fd)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{32         int (*close)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{33         void (*write\_enable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{34         void (*write\_disable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{35         void (*read\_enable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{36         void (*read\_disable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{37         void (*notify\_connected)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{38 \};}
\DoxyCodeLine{39 }
\DoxyCodeLine{40 \textcolor{preprocessor}{\#define IOFD\_FLAG\_CLOSED (1<<0)}}
\DoxyCodeLine{41 \textcolor{preprocessor}{\#define IOFD\_FLAG\_IN\_CALLBACK (1<<1)}}
\DoxyCodeLine{42 \textcolor{preprocessor}{\#define IOFD\_FLAG\_TO\_FREE (1<<2)}}
\DoxyCodeLine{43 \textcolor{preprocessor}{\#define IOFD\_FLAG\_NOTIFY\_CONNECTED (1<<3)}}
\DoxyCodeLine{44 \textcolor{preprocessor}{\#define IOFD\_FLAG\_FD\_REGISTERED (1<<4)}}
\DoxyCodeLine{45 }
\DoxyCodeLine{46 \textcolor{preprocessor}{\#define IOFD\_FLAG\_SET(iofd, flag) \(\backslash\)}}
\DoxyCodeLine{47 \textcolor{preprocessor}{        (iofd)-\/>flags |= (flag)}}
\DoxyCodeLine{48 }
\DoxyCodeLine{49 \textcolor{preprocessor}{\#define IOFD\_FLAG\_UNSET(iofd, flag) \(\backslash\)}}
\DoxyCodeLine{50 \textcolor{preprocessor}{        (iofd)-\/>flags \&= \string~(flag)}}
\DoxyCodeLine{51 }
\DoxyCodeLine{52 \textcolor{preprocessor}{\#define IOFD\_FLAG\_ISSET(iofd, flag) ((iofd)-\/>flags \& (flag))}}
\DoxyCodeLine{53 }
\DoxyCodeLine{54 \textcolor{preprocessor}{\#define IOFD\_MSGHDR\_MAX\_READ\_SQES       32}}
\DoxyCodeLine{55 }
\DoxyCodeLine{56 \textcolor{keyword}{struct }osmo\_io\_fd \{}
\DoxyCodeLine{58         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{60         \textcolor{keywordtype}{int} fd;}
\DoxyCodeLine{62         \textcolor{keyword}{enum} osmo\_io\_fd\_mode mode;}
\DoxyCodeLine{63 }
\DoxyCodeLine{65         uint32\_t flags;}
\DoxyCodeLine{66 }
\DoxyCodeLine{68         \textcolor{keywordtype}{char} *name;}
\DoxyCodeLine{69 }
\DoxyCodeLine{71         \textcolor{keyword}{struct }osmo\_io\_ops io\_ops;}
\DoxyCodeLine{73         \textcolor{keyword}{struct }msgb *pending;}
\DoxyCodeLine{74 }
\DoxyCodeLine{76         \textcolor{keywordtype}{void} *data;}
\DoxyCodeLine{78         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} priv\_nr;}
\DoxyCodeLine{79 }
\DoxyCodeLine{81         \textcolor{keywordtype}{size\_t} cmsg\_size;}
\DoxyCodeLine{82 }
\DoxyCodeLine{84         uint8\_t io\_read\_buffers;}
\DoxyCodeLine{85 }
\DoxyCodeLine{87         uint8\_t io\_write\_buffers;}
\DoxyCodeLine{88 }
\DoxyCodeLine{89         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{91                 \textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx;}
\DoxyCodeLine{93                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} size;}
\DoxyCodeLine{95                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} headroom;}
\DoxyCodeLine{96         \} msgb\_alloc;}
\DoxyCodeLine{97 }
\DoxyCodeLine{98         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{100                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} max\_length;}
\DoxyCodeLine{102                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} current\_length;}
\DoxyCodeLine{104                 \textcolor{keyword}{struct }llist\_head msg\_queue;}
\DoxyCodeLine{105         \} tx\_queue;}
\DoxyCodeLine{106 }
\DoxyCodeLine{107         \textcolor{keyword}{union }\{}
\DoxyCodeLine{108                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{109                         \textcolor{keyword}{struct }osmo\_fd ofd;}
\DoxyCodeLine{110                 \} poll;}
\DoxyCodeLine{111                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{112                         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{114                                 \textcolor{keywordtype}{bool} enabled;}
\DoxyCodeLine{116                                 uint8\_t num\_sqes;}
\DoxyCodeLine{118                                 \textcolor{keywordtype}{void} *msghdr[IOFD\_MSGHDR\_MAX\_READ\_SQES];}
\DoxyCodeLine{120                                 \textcolor{keyword}{struct }io\_uring *ring;}
\DoxyCodeLine{122                                 uint8\_t sqes\_submitted;}
\DoxyCodeLine{123                         \} read;}
\DoxyCodeLine{124                         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{126                                 \textcolor{keywordtype}{bool} enabled;}
\DoxyCodeLine{128                                 \textcolor{keywordtype}{void} *msghdr;}
\DoxyCodeLine{130                                 \textcolor{keyword}{struct }io\_uring *ring;}
\DoxyCodeLine{131                         \} write;}
\DoxyCodeLine{132                         \textcolor{comment}{/* TODO: index into array of registered fd's? */}}
\DoxyCodeLine{133                         \textcolor{comment}{/* osmo\_fd for non-\/blocking connect handling */}}
\DoxyCodeLine{134                         \textcolor{keyword}{struct }osmo\_fd connect\_ofd;}
\DoxyCodeLine{135                 \} uring;}
\DoxyCodeLine{136         \} u;}
\DoxyCodeLine{137 \};}
\DoxyCodeLine{138 }
\DoxyCodeLine{139 \textcolor{keyword}{enum} iofd\_msg\_action \{}
\DoxyCodeLine{140         IOFD\_ACT\_READ,}
\DoxyCodeLine{141         IOFD\_ACT\_WRITE,}
\DoxyCodeLine{142         IOFD\_ACT\_RECVFROM,}
\DoxyCodeLine{143         IOFD\_ACT\_SENDTO,}
\DoxyCodeLine{144         IOFD\_ACT\_RECVMSG,}
\DoxyCodeLine{145         IOFD\_ACT\_SENDMSG,}
\DoxyCodeLine{146 \};}
\DoxyCodeLine{147 }
\DoxyCodeLine{148 \textcolor{preprocessor}{\#define IOFD\_MSGHDR\_IO\_BUFFERS  8}}
\DoxyCodeLine{149 }
\DoxyCodeLine{151 \textcolor{keyword}{struct }iofd\_msghdr \{}
\DoxyCodeLine{153         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{154         \textcolor{keyword}{enum} iofd\_msg\_action action;}
\DoxyCodeLine{156         \textcolor{keyword}{struct }msghdr hdr;}
\DoxyCodeLine{158         \textcolor{keyword}{struct }osmo\_sockaddr osa;}
\DoxyCodeLine{161         \textcolor{keyword}{struct }iovec iov[IOFD\_MSGHDR\_IO\_BUFFERS];}
\DoxyCodeLine{163         \textcolor{keywordtype}{int} flags;}
\DoxyCodeLine{164 }
\DoxyCodeLine{166         uint8\_t io\_len;}
\DoxyCodeLine{168         \textcolor{keyword}{struct }msgb *msg[IOFD\_MSGHDR\_IO\_BUFFERS];}
\DoxyCodeLine{170         \textcolor{keyword}{struct }osmo\_io\_fd *iofd;}
\DoxyCodeLine{171 }
\DoxyCodeLine{173         \textcolor{keywordtype}{bool} in\_cancel\_queue;}
\DoxyCodeLine{174 }
\DoxyCodeLine{179         \textcolor{keywordtype}{char} \_Alignas(\textcolor{keyword}{struct} cmsghdr) cmsg[0];}
\DoxyCodeLine{180 \};}
\DoxyCodeLine{181 }
\DoxyCodeLine{182 \textcolor{keyword}{enum} iofd\_seg\_act \{}
\DoxyCodeLine{183         IOFD\_SEG\_ACT\_HANDLE\_ONE,}
\DoxyCodeLine{184         IOFD\_SEG\_ACT\_HANDLE\_MORE,}
\DoxyCodeLine{185         IOFD\_SEG\_ACT\_DEFER,}
\DoxyCodeLine{186 \};}
\DoxyCodeLine{187 }
\DoxyCodeLine{188 \textcolor{keyword}{struct }iofd\_msghdr *iofd\_msghdr\_alloc(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{enum} iofd\_msg\_action action, \textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{size\_t} cmsg\_size);}
\DoxyCodeLine{189 \textcolor{keywordtype}{void} iofd\_msghdr\_free(\textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{190 }
\DoxyCodeLine{191 \textcolor{keyword}{struct }msgb *iofd\_msgb\_alloc2(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{size\_t} size);}
\DoxyCodeLine{192 \textcolor{keyword}{struct }msgb *iofd\_msgb\_alloc(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{193 }
\DoxyCodeLine{194 \textcolor{keywordtype}{void} iofd\_handle\_recv(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} rc, \textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{195 \textcolor{keywordtype}{void} iofd\_handle\_send\_completion(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} rc, \textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{196 }
\DoxyCodeLine{197 \textcolor{keywordtype}{int} iofd\_txqueue\_enqueue(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{198 \textcolor{keywordtype}{void} iofd\_txqueue\_enqueue\_front(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{199 \textcolor{keyword}{struct }iofd\_msghdr *iofd\_txqueue\_dequeue(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}

\end{DoxyCode}
