\doxysection{src/core/osmo\+\_\+io.c File Reference}
\label{osmo__io_8c}\index{src/core/osmo\_io.c@{src/core/osmo\_io.c}}
{\ttfamily \#include \char`\"{}../config.\+h\char`\"{}}\newline
{\ttfamily \#include $<$fcntl.\+h$>$}\newline
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$talloc.\+h$>$}\newline
{\ttfamily \#include $<$unistd.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$stdbool.\+h$>$}\newline
{\ttfamily \#include $<$errno.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/osmo\+\_\+io.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/linuxlist.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/logging.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/msgb.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/socket.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline
{\ttfamily \#include \char`\"{}osmo\+\_\+io\+\_\+internal.\+h\char`\"{}}\newline
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ OSMO\+\_\+\+IO\+\_\+\+BACKEND\+\_\+\+ENV}~\char`\"{}LIBOSMO\+\_\+\+IO\+\_\+\+BACKEND\char`\"{}
\begin{DoxyCompactList}\small\item\em This environment variable can be set to manually set the backend used in osmo\+\_\+io. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \textbf{ osmo\+\_\+iofd\+\_\+init} (void)
\begin{DoxyCompactList}\small\item\em initialize osmo\+\_\+io for the current thread \end{DoxyCompactList}\item 
static \textbf{ \+\_\+\+\_\+attribute\+\_\+\+\_\+} ((constructor(103)))
\item 
struct \textbf{ iofd\+\_\+msghdr} $\ast$ \textbf{ iofd\+\_\+msghdr\+\_\+alloc} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, enum \textbf{ iofd\+\_\+msg\+\_\+action} action, struct \textbf{ msgb} $\ast$\textbf{ msg}, size\+\_\+t cmsg\+\_\+size)
\begin{DoxyCompactList}\small\item\em Allocate the msghdr. \end{DoxyCompactList}\item 
void \textbf{ iofd\+\_\+msghdr\+\_\+free} (struct \textbf{ iofd\+\_\+msghdr} $\ast$msghdr)
\begin{DoxyCompactList}\small\item\em Free the msghdr. \end{DoxyCompactList}\item 
struct \textbf{ msgb} $\ast$ \textbf{ iofd\+\_\+msgb\+\_\+alloc} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em convenience wrapper to call msgb\+\_\+alloc with parameters from \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd} \end{DoxyCompactList}\item 
struct \textbf{ msgb} $\ast$ \textbf{ iofd\+\_\+msgb\+\_\+pending} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em return the pending msgb in iofd or NULL if there is none \end{DoxyCompactList}\item 
struct \textbf{ msgb} $\ast$ \textbf{ iofd\+\_\+msgb\+\_\+pending\+\_\+or\+\_\+alloc} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Return the pending msgb or allocate and return a new one. \end{DoxyCompactList}\item 
int \textbf{ iofd\+\_\+txqueue\+\_\+enqueue} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ iofd\+\_\+msghdr} $\ast$msghdr)
\begin{DoxyCompactList}\small\item\em Enqueue a message to be sent. \end{DoxyCompactList}\item 
void \textbf{ iofd\+\_\+txqueue\+\_\+enqueue\+\_\+front} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ iofd\+\_\+msghdr} $\ast$msghdr)
\begin{DoxyCompactList}\small\item\em Enqueue a message at the front. \end{DoxyCompactList}\item 
struct \textbf{ iofd\+\_\+msghdr} $\ast$ \textbf{ iofd\+\_\+txqueue\+\_\+dequeue} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Dequeue a message from the front. \end{DoxyCompactList}\item 
static enum \textbf{ iofd\+\_\+seg\+\_\+act} \textbf{ iofd\+\_\+handle\+\_\+segmentation} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ msgb} $\ast$\textbf{ msg}, struct \textbf{ msgb} $\ast$$\ast$pending\+\_\+out)
\begin{DoxyCompactList}\small\item\em Handle segmentation of the msg. \end{DoxyCompactList}\item 
void \textbf{ iofd\+\_\+handle\+\_\+segmented\+\_\+read} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ msgb} $\ast$\textbf{ msg}, int rc)
\begin{DoxyCompactList}\small\item\em Restore message boundaries on read() and pass individual messages to the read callback. \end{DoxyCompactList}\item 
void \textbf{ iofd\+\_\+handle\+\_\+recv} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ msgb} $\ast$\textbf{ msg}, int rc, struct \textbf{ iofd\+\_\+msghdr} $\ast$\textbf{ hdr})
\begin{DoxyCompactList}\small\item\em completion handler\+: Internal function called by osmo\+\_\+io\+\_\+backend after a given I/O operation has completed \end{DoxyCompactList}\item 
void \textbf{ iofd\+\_\+handle\+\_\+send\+\_\+completion} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, int rc, struct \textbf{ iofd\+\_\+msghdr} $\ast$msghdr)
\begin{DoxyCompactList}\small\item\em completion handler\+: Internal function called by osmo\+\_\+io\+\_\+backend after a given I/O operation has completed \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+write\+\_\+msgb} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ msgb} $\ast$\textbf{ msg})
\begin{DoxyCompactList}\small\item\em Write a message to a file descriptor / connected socket. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+sendto\+\_\+msgb} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ msgb} $\ast$\textbf{ msg}, int sendto\+\_\+flags, const struct \textbf{ osmo\+\_\+sockaddr} $\ast$dest)
\begin{DoxyCompactList}\small\item\em Send a message through an unconnected socket. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+sendmsg\+\_\+msgb} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ msgb} $\ast$\textbf{ msg}, int sendmsg\+\_\+flags, const struct msghdr $\ast$msgh)
\begin{DoxyCompactList}\small\item\em osmo\+\_\+io equivalent of the sendmsg(2) socket API call. \end{DoxyCompactList}\item 
static int \textbf{ check\+\_\+mode\+\_\+callback\+\_\+compat} (enum \textbf{ osmo\+\_\+io\+\_\+fd\+\_\+mode} \textbf{ mode}, const struct \textbf{ osmo\+\_\+io\+\_\+ops} $\ast$ops)
\item 
struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$ \textbf{ osmo\+\_\+iofd\+\_\+setup} (const void $\ast$ctx, int fd, const char $\ast$\textbf{ name}, enum \textbf{ osmo\+\_\+io\+\_\+fd\+\_\+mode} \textbf{ mode}, const struct \textbf{ osmo\+\_\+io\+\_\+ops} $\ast$ioops, void $\ast$\textbf{ data})
\begin{DoxyCompactList}\small\item\em Allocate and setup a new iofd. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+cmsg\+\_\+size} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, size\+\_\+t cmsg\+\_\+size)
\begin{DoxyCompactList}\small\item\em Set the size of the control message buffer allocated when submitting recvmsg. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+register} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, int fd)
\begin{DoxyCompactList}\small\item\em Register the \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd} for active I/O. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+unregister} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Unregister the given \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd} from osmo\+\_\+io. \end{DoxyCompactList}\item 
unsigned int \textbf{ osmo\+\_\+iofd\+\_\+txqueue\+\_\+len} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Retrieve the number of messages pending in the transmit queue. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+txqueue\+\_\+clear} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Clear the transmit queue of the given \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+free} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Free the given \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+close} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Close the given \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+alloc\+\_\+info} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, unsigned int size, unsigned int headroom)
\begin{DoxyCompactList}\small\item\em Set the size and headroom of the msgb allocated when receiving messages. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+txqueue\+\_\+max\+\_\+length} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, unsigned int max\+\_\+length)
\begin{DoxyCompactList}\small\item\em Set the maximum number of messages enqueued for sending. \end{DoxyCompactList}\item 
void $\ast$ \textbf{ osmo\+\_\+iofd\+\_\+get\+\_\+data} (const struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Retrieve the associated user-\/data from an \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+data} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, void $\ast$\textbf{ data})
\begin{DoxyCompactList}\small\item\em Set the associated user-\/data from an \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
unsigned int \textbf{ osmo\+\_\+iofd\+\_\+get\+\_\+priv\+\_\+nr} (const struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Retrieve the private number from an \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+priv\+\_\+nr} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, unsigned int priv\+\_\+nr)
\begin{DoxyCompactList}\small\item\em Set the private number of an \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+get\+\_\+fd} (const struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Retrieve the underlying file descriptor from an \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+iofd\+\_\+get\+\_\+name} (const struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Retrieve the human-\/readable name of the given \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+name} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, const char $\ast$\textbf{ name})
\begin{DoxyCompactList}\small\item\em Set the human-\/readable name of the file descriptor. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+ioops} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, const struct \textbf{ osmo\+\_\+io\+\_\+ops} $\ast$ioops)
\begin{DoxyCompactList}\small\item\em Set the \doxyref{osmo\+\_\+io\+\_\+ops}{p.}{structosmo__io__ops} calbacks for an \doxyref{osmo\+\_\+io\+\_\+fd}{p.}{structosmo__io__fd}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+get\+\_\+ioops} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd, struct \textbf{ osmo\+\_\+io\+\_\+ops} $\ast$ioops)
\begin{DoxyCompactList}\small\item\em Retrieve the \doxyref{osmo\+\_\+io\+\_\+ops}{p.}{structosmo__io__ops} for an iofd. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+iofd\+\_\+notify\+\_\+connected} (struct \textbf{ osmo\+\_\+io\+\_\+fd} $\ast$iofd)
\begin{DoxyCompactList}\small\item\em Request notification of the user if/when a client socket is connected. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
const struct \textbf{ value\+\_\+string} \textbf{ osmo\+\_\+io\+\_\+backend\+\_\+names} [$\,$]
\item 
const struct \textbf{ value\+\_\+string} \textbf{ osmo\+\_\+iofd\+\_\+mode\+\_\+names} [$\,$]
\item 
static enum \textbf{ osmo\+\_\+io\+\_\+backend} \textbf{ g\+\_\+io\+\_\+backend}
\item 
struct \textbf{ iofd\+\_\+backend\+\_\+ops} \textbf{ osmo\+\_\+iofd\+\_\+ops}
\end{DoxyCompactItemize}
