\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 <unistd.h>}}
\DoxyCodeLine{6 \textcolor{preprocessor}{\#include <stdbool.h>}}
\DoxyCodeLine{7 \textcolor{preprocessor}{\#include <netinet/sctp.h>}}
\DoxyCodeLine{8 }
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <osmocom/core/osmo\_io.h>}}
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{11 \textcolor{preprocessor}{\#include <osmocom/core/msgb.h>}}
\DoxyCodeLine{12 \textcolor{preprocessor}{\#include <osmocom/core/select.h>}}
\DoxyCodeLine{13 \textcolor{preprocessor}{\#include <osmocom/core/socket.h>}}
\DoxyCodeLine{14 }
\DoxyCodeLine{15 \textcolor{preprocessor}{\#include "{}../config.h"{}}}
\DoxyCodeLine{16 }
\DoxyCodeLine{17 \textcolor{preprocessor}{\#define OSMO\_IO\_DEFAULT\_MSGB\_SIZE 1024}}
\DoxyCodeLine{18 \textcolor{preprocessor}{\#define OSMO\_IO\_DEFAULT\_MSGB\_HEADROOM 128}}
\DoxyCodeLine{19 }
\DoxyCodeLine{20 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }iofd\_backend\_ops iofd\_poll\_ops;}
\DoxyCodeLine{21 \textcolor{preprocessor}{\#define OSMO\_IO\_BACKEND\_DEFAULT "{}POLL"{}}}
\DoxyCodeLine{22 }
\DoxyCodeLine{23 \textcolor{preprocessor}{\#if defined(HAVE\_URING)}}
\DoxyCodeLine{24 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }iofd\_backend\_ops iofd\_uring\_ops;}
\DoxyCodeLine{25 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{26 }
\DoxyCodeLine{27 \textcolor{keyword}{struct }iofd\_backend\_ops \{}
\DoxyCodeLine{28         int (*register\_fd)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{29         int (*unregister\_fd)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{30         int (*close)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{31         void (*write\_enable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{32         void (*write\_disable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{33         void (*read\_enable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{34         void (*read\_disable)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{35         void (*notify\_connected)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd);}
\DoxyCodeLine{36 \};}
\DoxyCodeLine{37 }
\DoxyCodeLine{38 \textcolor{preprocessor}{\#define IOFD\_FLAG\_CLOSED (1<<0)}}
\DoxyCodeLine{39 \textcolor{preprocessor}{\#define IOFD\_FLAG\_IN\_CALLBACK (1<<1)}}
\DoxyCodeLine{40 \textcolor{preprocessor}{\#define IOFD\_FLAG\_TO\_FREE (1<<2)}}
\DoxyCodeLine{41 \textcolor{preprocessor}{\#define IOFD\_FLAG\_NOTIFY\_CONNECTED (1<<3)}}
\DoxyCodeLine{42 \textcolor{preprocessor}{\#define IOFD\_FLAG\_FD\_REGISTERED (1<<4)}}
\DoxyCodeLine{43 }
\DoxyCodeLine{44 \textcolor{preprocessor}{\#define IOFD\_FLAG\_SET(iofd, flag) \(\backslash\)}}
\DoxyCodeLine{45 \textcolor{preprocessor}{        (iofd)-\/>flags |= (flag)}}
\DoxyCodeLine{46 }
\DoxyCodeLine{47 \textcolor{preprocessor}{\#define IOFD\_FLAG\_UNSET(iofd, flag) \(\backslash\)}}
\DoxyCodeLine{48 \textcolor{preprocessor}{        (iofd)-\/>flags \&= \string~(flag)}}
\DoxyCodeLine{49 }
\DoxyCodeLine{50 \textcolor{preprocessor}{\#define IOFD\_FLAG\_ISSET(iofd, flag) ((iofd)-\/>flags \& (flag))}}
\DoxyCodeLine{51 }
\DoxyCodeLine{52 \textcolor{keyword}{struct }osmo\_io\_fd \{}
\DoxyCodeLine{54         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{56         \textcolor{keywordtype}{int} fd;}
\DoxyCodeLine{58         \textcolor{keyword}{enum} osmo\_io\_fd\_mode mode;}
\DoxyCodeLine{59 }
\DoxyCodeLine{61         uint32\_t flags;}
\DoxyCodeLine{62 }
\DoxyCodeLine{64         \textcolor{keywordtype}{char} *name;}
\DoxyCodeLine{65 }
\DoxyCodeLine{67         \textcolor{keyword}{struct }osmo\_io\_ops io\_ops;}
\DoxyCodeLine{69         \textcolor{keyword}{struct }msgb *pending;}
\DoxyCodeLine{70 }
\DoxyCodeLine{72         \textcolor{keywordtype}{void} *data;}
\DoxyCodeLine{74         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} priv\_nr;}
\DoxyCodeLine{75 }
\DoxyCodeLine{77         \textcolor{keywordtype}{size\_t} cmsg\_size;}
\DoxyCodeLine{78 }
\DoxyCodeLine{79         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{81                 \textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx;}
\DoxyCodeLine{83                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} size;}
\DoxyCodeLine{85                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} headroom;}
\DoxyCodeLine{86         \} msgb\_alloc;}
\DoxyCodeLine{87 }
\DoxyCodeLine{88         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{90                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} max\_length;}
\DoxyCodeLine{92                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} current\_length;}
\DoxyCodeLine{94                 \textcolor{keyword}{struct }llist\_head msg\_queue;}
\DoxyCodeLine{95         \} tx\_queue;}
\DoxyCodeLine{96 }
\DoxyCodeLine{97         \textcolor{keyword}{union }\{}
\DoxyCodeLine{98                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{99                         \textcolor{keyword}{struct }osmo\_fd ofd;}
\DoxyCodeLine{100                 \} poll;}
\DoxyCodeLine{101                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{102                         \textcolor{keywordtype}{bool} read\_enabled;}
\DoxyCodeLine{103                         \textcolor{keywordtype}{bool} write\_enabled;}
\DoxyCodeLine{104                         \textcolor{keywordtype}{void} *read\_msghdr;}
\DoxyCodeLine{105                         \textcolor{keywordtype}{void} *write\_msghdr;}
\DoxyCodeLine{106                         \textcolor{comment}{/* TODO: index into array of registered fd's? */}}
\DoxyCodeLine{107                         \textcolor{comment}{/* osmo\_fd for non-\/blocking connect handling */}}
\DoxyCodeLine{108                         \textcolor{keyword}{struct }osmo\_fd connect\_ofd;}
\DoxyCodeLine{109                 \} uring;}
\DoxyCodeLine{110         \} u;}
\DoxyCodeLine{111 \};}
\DoxyCodeLine{112 }
\DoxyCodeLine{113 \textcolor{keyword}{enum} iofd\_msg\_action \{}
\DoxyCodeLine{114         IOFD\_ACT\_READ,}
\DoxyCodeLine{115         IOFD\_ACT\_WRITE,}
\DoxyCodeLine{116         IOFD\_ACT\_RECVFROM,}
\DoxyCodeLine{117         IOFD\_ACT\_SENDTO,}
\DoxyCodeLine{118         IOFD\_ACT\_RECVMSG,}
\DoxyCodeLine{119         IOFD\_ACT\_SENDMSG,}
\DoxyCodeLine{120 \};}
\DoxyCodeLine{121 }
\DoxyCodeLine{122 }
\DoxyCodeLine{124 \textcolor{keyword}{struct }iofd\_msghdr \{}
\DoxyCodeLine{126         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{127         \textcolor{keyword}{enum} iofd\_msg\_action action;}
\DoxyCodeLine{129         \textcolor{keyword}{struct }msghdr hdr;}
\DoxyCodeLine{131         \textcolor{keyword}{struct }osmo\_sockaddr osa;}
\DoxyCodeLine{134         \textcolor{keyword}{struct }iovec iov[1];}
\DoxyCodeLine{136         \textcolor{keywordtype}{int} flags;}
\DoxyCodeLine{137 }
\DoxyCodeLine{139         \textcolor{keyword}{struct }msgb *msg;}
\DoxyCodeLine{141         \textcolor{keyword}{struct }osmo\_io\_fd *iofd;}
\DoxyCodeLine{142 }
\DoxyCodeLine{144         \textcolor{keywordtype}{char} cmsg[0]; \textcolor{comment}{/* size is determined by iofd-\/>cmsg\_size on recvmsg, and by mcghdr-\/>msg\_controllen on sendmsg */}}
\DoxyCodeLine{145 \};}
\DoxyCodeLine{146 }
\DoxyCodeLine{147 \textcolor{keyword}{enum} iofd\_seg\_act \{}
\DoxyCodeLine{148         IOFD\_SEG\_ACT\_HANDLE\_ONE,}
\DoxyCodeLine{149         IOFD\_SEG\_ACT\_HANDLE\_MORE,}
\DoxyCodeLine{150         IOFD\_SEG\_ACT\_DEFER,}
\DoxyCodeLine{151 \};}
\DoxyCodeLine{152 }
\DoxyCodeLine{153 \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{154 \textcolor{keywordtype}{void} iofd\_msghdr\_free(\textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{155 }
\DoxyCodeLine{156 \textcolor{keyword}{struct }msgb *iofd\_msgb\_alloc(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{157 \textcolor{keyword}{struct }msgb *iofd\_msgb\_pending(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{158 \textcolor{keyword}{struct }msgb *iofd\_msgb\_pending\_or\_alloc(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{159 }
\DoxyCodeLine{160 \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{161 \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{162 \textcolor{keywordtype}{void} iofd\_handle\_segmented\_read(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} rc);}
\DoxyCodeLine{163 }
\DoxyCodeLine{164 \textcolor{keywordtype}{int} iofd\_txqueue\_enqueue(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{165 \textcolor{keywordtype}{void} iofd\_txqueue\_enqueue\_front(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} iofd\_msghdr *msghdr);}
\DoxyCodeLine{166 \textcolor{keyword}{struct }iofd\_msghdr *iofd\_txqueue\_dequeue(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}

\end{DoxyCode}
