\doxysection{osmo\+\_\+io.\+h}
\label{osmo__io_8h_source}\index{include/osmocom/core/osmo\_io.h@{include/osmocom/core/osmo\_io.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{5 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{6 }
\DoxyCodeLine{7 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <osmocom/core/logging.h>}}
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <osmocom/core/msgb.h>}}
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <osmocom/core/socket.h>}}
\DoxyCodeLine{11 \textcolor{preprocessor}{\#include <osmocom/core/utils.h>}}
\DoxyCodeLine{12 }
\DoxyCodeLine{13 \textcolor{comment}{/* struct msghdr is defined in sys/socket.h but that header may not be available.}}
\DoxyCodeLine{14 \textcolor{comment}{ * We only really need a forward declaration here: */}}
\DoxyCodeLine{15 \textcolor{keyword}{struct }msghdr;}
\DoxyCodeLine{16 }
\DoxyCodeLine{59 \textcolor{preprocessor}{\#define LOGPIO(iofd, level, fmt, args...) \(\backslash\)}}
\DoxyCodeLine{60 \textcolor{preprocessor}{        LOGP(DLIO, level, "{}iofd(\%s) "{}} fmt, iofd-\/>name, \#\# args)}
\DoxyCodeLine{61 }
\DoxyCodeLine{62 \textcolor{keyword}{struct }osmo\_io\_fd;}
\DoxyCodeLine{63 }
\DoxyCodeLine{66 \textcolor{keyword}{enum} osmo\_io\_fd\_mode \{}
\DoxyCodeLine{68         OSMO\_IO\_FD\_MODE\_READ\_WRITE,}
\DoxyCodeLine{70         OSMO\_IO\_FD\_MODE\_RECVFROM\_SENDTO,}
\DoxyCodeLine{72         OSMO\_IO\_FD\_MODE\_RECVMSG\_SENDMSG,}
\DoxyCodeLine{73 \};}
\DoxyCodeLine{74 }
\DoxyCodeLine{76 \textcolor{keyword}{enum} osmo\_io\_op \{}
\DoxyCodeLine{78         OSMO\_IO\_OP\_READ,}
\DoxyCodeLine{80         OSMO\_IO\_OP\_WRITE,}
\DoxyCodeLine{81 \};}
\DoxyCodeLine{82 }
\DoxyCodeLine{85 \textcolor{keyword}{enum} osmo\_io\_backend \{}
\DoxyCodeLine{87         OSMO\_IO\_BACKEND\_POLL,}
\DoxyCodeLine{89         OSMO\_IO\_BACKEND\_IO\_URING,}
\DoxyCodeLine{90 \};}
\DoxyCodeLine{91 }
\DoxyCodeLine{92 \textcolor{keyword}{enum} osmo\_io\_backend osmo\_io\_get\_backend(\textcolor{keywordtype}{void});}
\DoxyCodeLine{93 }
\DoxyCodeLine{94 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }value\_string osmo\_io\_backend\_names[];}
\DoxyCodeLine{96 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *osmo\_io\_backend\_name(\textcolor{keyword}{enum} osmo\_io\_backend val)}
\DoxyCodeLine{97 \{ \textcolor{keywordflow}{return} get\_value\_string(osmo\_io\_backend\_names, val); \}}
\DoxyCodeLine{98 }
\DoxyCodeLine{99 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }value\_string osmo\_iofd\_mode\_names[];}
\DoxyCodeLine{101 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *osmo\_iofd\_mode\_name(\textcolor{keyword}{enum} osmo\_io\_fd\_mode val)}
\DoxyCodeLine{102 \{ \textcolor{keywordflow}{return} get\_value\_string(osmo\_iofd\_mode\_names, val); \}}
\DoxyCodeLine{103 }
\DoxyCodeLine{105 \textcolor{keyword}{struct }osmo\_io\_ops \{}
\DoxyCodeLine{106         \textcolor{comment}{/* mode OSMO\_IO\_FD\_MODE\_READ\_WRITE: */}}
\DoxyCodeLine{107         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{118                 void (*read\_cb)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} res, \textcolor{keyword}{struct }msgb *msg);}
\DoxyCodeLine{119 }
\DoxyCodeLine{126                 void (*write\_cb)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} res,}
\DoxyCodeLine{127                                  \textcolor{keyword}{struct }msgb *msg);}
\DoxyCodeLine{128 }
\DoxyCodeLine{148                 int (*segmentation\_cb)(\textcolor{keyword}{struct }msgb *msg);}
\DoxyCodeLine{149 }
\DoxyCodeLine{163                 int (*segmentation\_cb2)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keyword}{struct }msgb *msg);}
\DoxyCodeLine{164         \};}
\DoxyCodeLine{165 }
\DoxyCodeLine{166         \textcolor{comment}{/* mode OSMO\_IO\_FD\_MODE\_RECVFROM\_SENDTO: */}}
\DoxyCodeLine{167         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{175                 void (*recvfrom\_cb)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} res,}
\DoxyCodeLine{176                                     \textcolor{keyword}{struct }msgb *msg,}
\DoxyCodeLine{177                                     \textcolor{keyword}{const} \textcolor{keyword}{struct }osmo\_sockaddr *saddr);}
\DoxyCodeLine{185                 void (*sendto\_cb)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} res,}
\DoxyCodeLine{186                                   \textcolor{keyword}{struct }msgb *msg,}
\DoxyCodeLine{187                                   \textcolor{keyword}{const} \textcolor{keyword}{struct }osmo\_sockaddr *daddr);}
\DoxyCodeLine{188         \};}
\DoxyCodeLine{189 }
\DoxyCodeLine{190         \textcolor{comment}{/* mode OSMO\_IO\_FD\_MODE\_RECVMSG\_SENDMSG: */}}
\DoxyCodeLine{191         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{200                 void (*recvmsg\_cb)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} res,}
\DoxyCodeLine{201                                    \textcolor{keyword}{struct }msgb *msg, \textcolor{keyword}{const} \textcolor{keyword}{struct }msghdr *msgh);}
\DoxyCodeLine{208                 void (*sendmsg\_cb)(\textcolor{keyword}{struct }osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} res, \textcolor{keyword}{struct }msgb *msg);}
\DoxyCodeLine{209         \};}
\DoxyCodeLine{210 \};}
\DoxyCodeLine{211 }
\DoxyCodeLine{212 \textcolor{keywordtype}{void} osmo\_iofd\_init(\textcolor{keywordtype}{void});}
\DoxyCodeLine{213 }
\DoxyCodeLine{214 \textcolor{keyword}{struct }osmo\_io\_fd *osmo\_iofd\_setup(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, \textcolor{keywordtype}{int} fd, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name,}
\DoxyCodeLine{215                   \textcolor{keyword}{enum} osmo\_io\_fd\_mode mode, \textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_ops *ioops, \textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{216 \textcolor{keywordtype}{int} osmo\_iofd\_set\_cmsg\_size(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{size\_t} cmsg\_size);}
\DoxyCodeLine{217 \textcolor{keywordtype}{int} osmo\_iofd\_set\_io\_buffers(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{enum} osmo\_io\_op op, uint8\_t buffers);}
\DoxyCodeLine{218 \textcolor{keywordtype}{int} osmo\_iofd\_set\_sqes(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{enum} osmo\_io\_op op, uint8\_t sqes);}
\DoxyCodeLine{219 \textcolor{keywordtype}{int} osmo\_iofd\_register(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{int} fd);}
\DoxyCodeLine{220 \textcolor{keywordtype}{int} osmo\_iofd\_unregister(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{221 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} osmo\_iofd\_txqueue\_len(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{222 \textcolor{keywordtype}{void} osmo\_iofd\_txqueue\_clear(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{223 \textcolor{keywordtype}{int} osmo\_iofd\_close(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{224 \textcolor{keywordtype}{void} osmo\_iofd\_free(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{225 }
\DoxyCodeLine{226 \textcolor{keywordtype}{void} osmo\_iofd\_notify\_connected(\textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{227 }
\DoxyCodeLine{228 \textcolor{keywordtype}{int} osmo\_iofd\_write\_msgb(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} msgb *msg);}
\DoxyCodeLine{229 \textcolor{keywordtype}{int} osmo\_iofd\_sendto\_msgb(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} sendto\_flags,}
\DoxyCodeLine{230                           \textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_sockaddr *dest);}
\DoxyCodeLine{231 \textcolor{keywordtype}{int} osmo\_iofd\_sendmsg\_msgb(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} sendmsg\_flags,}
\DoxyCodeLine{232                            \textcolor{keyword}{const} \textcolor{keyword}{struct} msghdr *msgh);}
\DoxyCodeLine{233 }
\DoxyCodeLine{234 \textcolor{keywordtype}{void} osmo\_iofd\_set\_alloc\_info(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} size, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} headroom);}
\DoxyCodeLine{235 \textcolor{keywordtype}{void} osmo\_iofd\_set\_txqueue\_max\_length(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} size);}
\DoxyCodeLine{236 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} osmo\_iofd\_get\_txqueue\_max\_length(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{237 \textcolor{keywordtype}{void} *osmo\_iofd\_get\_data(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{238 \textcolor{keywordtype}{void} osmo\_iofd\_set\_data(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{void} *data);}
\DoxyCodeLine{239 }
\DoxyCodeLine{240 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} osmo\_iofd\_get\_priv\_nr(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{241 \textcolor{keywordtype}{void} osmo\_iofd\_set\_priv\_nr(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} priv\_nr);}
\DoxyCodeLine{242 }
\DoxyCodeLine{243 \textcolor{keywordtype}{int} osmo\_iofd\_get\_fd(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{244 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *osmo\_iofd\_get\_name(\textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_fd *iofd);}
\DoxyCodeLine{245 \textcolor{keywordtype}{void} osmo\_iofd\_set\_name(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{246 \textcolor{keywordtype}{void} osmo\_iofd\_set\_name\_f(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *fmt, ...);}
\DoxyCodeLine{247 }
\DoxyCodeLine{248 \textcolor{keywordtype}{int} osmo\_iofd\_set\_ioops(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{const} \textcolor{keyword}{struct} osmo\_io\_ops *ioops);}
\DoxyCodeLine{249 \textcolor{keywordtype}{void} osmo\_iofd\_get\_ioops(\textcolor{keyword}{struct} osmo\_io\_fd *iofd, \textcolor{keyword}{struct} osmo\_io\_ops *ioops);}
\DoxyCodeLine{250 }

\end{DoxyCode}
