\doxysection{src/stream\+\_\+cli.c File Reference} \label{stream__cli_8c}\index{src/stream\_cli.c@{src/stream\_cli.c}} Osmocom stream socket helpers (client side) {\ttfamily \#include $<$stdio.\+h$>$}\newline {\ttfamily \#include $<$unistd.\+h$>$}\newline {\ttfamily \#include $<$stdlib.\+h$>$}\newline {\ttfamily \#include $<$errno.\+h$>$}\newline {\ttfamily \#include $<$string.\+h$>$}\newline {\ttfamily \#include $<$time.\+h$>$}\newline {\ttfamily \#include $<$sys/fcntl.\+h$>$}\newline {\ttfamily \#include $<$sys/socket.\+h$>$}\newline {\ttfamily \#include $<$sys/ioctl.\+h$>$}\newline {\ttfamily \#include $<$arpa/inet.\+h$>$}\newline {\ttfamily \#include $<$netinet/in.\+h$>$}\newline {\ttfamily \#include $<$netinet/tcp.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/timer.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/select.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline {\ttfamily \#include $<$osmocom/gsm/tlv.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/msgb.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/osmo\+\_\+io.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/panic.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/logging.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/socket.\+h$>$}\newline {\ttfamily \#include $<$osmocom/netif/stream.\+h$>$}\newline {\ttfamily \#include $<$osmocom/netif/stream\+\_\+private.\+h$>$}\newline {\ttfamily \#include \char`\"{}config.\+h\char`\"{}}\newline {\ttfamily \#include $<$osmocom/netif/sctp.\+h$>$}\newline \doxysubsection*{Data Structures} \begin{DoxyCompactItemize} \item struct \textbf{ osmo\+\_\+stream\+\_\+cli} \end{DoxyCompactItemize} \doxysubsection*{Macros} \begin{DoxyCompactItemize} \item \#define \textbf{ LOGSCLI}(cli, level, fmt, args...) \item \#define {\bfseries OSMO\+\_\+\+STREAM\+\_\+\+CLI\+\_\+\+F\+\_\+\+RECONF}~(1 $<$$<$ 0) \item \#define {\bfseries OSMO\+\_\+\+STREAM\+\_\+\+CLI\+\_\+\+F\+\_\+\+NODELAY}~(1 $<$$<$ 1) \end{DoxyCompactItemize} \doxysubsection*{Enumerations} \begin{DoxyCompactItemize} \item \mbox{\label{group__stream_gaefb240abea020971d9a384b5e39826e5}} enum {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+state} \{ \newline {\bfseries STREAM\+\_\+\+CLI\+\_\+\+STATE\+\_\+\+CLOSED} , {\bfseries STREAM\+\_\+\+CLI\+\_\+\+STATE\+\_\+\+WAIT\+\_\+\+RECONNECT} , {\bfseries STREAM\+\_\+\+CLI\+\_\+\+STATE\+\_\+\+CONNECTING} , {\bfseries STREAM\+\_\+\+CLI\+\_\+\+STATE\+\_\+\+CONNECTED} , \newline {\bfseries STREAM\+\_\+\+CLI\+\_\+\+STATE\+\_\+\+MAX} \} \end{DoxyCompactItemize} \doxysubsection*{Functions} \begin{DoxyCompactItemize} \item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+close} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Close an Osmocom Stream Client. \end{DoxyCompactList}\item void {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+reconnect} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Re-\/connect an Osmocom Stream Client If re-\/connection is enabled for this client (which is the case unless negative timeout was explicitly set via \doxyref{osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+reconnect\+\_\+timeout()}{p.}{group__stream_gade74792afe35f31dd2584c888db3dd62} call), we close any existing connection (if any) and schedule a re-\/connect timer. \end{DoxyCompactList}\item bool \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+is\+\_\+connected} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Check if Osmocom Stream Client is in connected state. \end{DoxyCompactList}\item static void {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+close\+\_\+iofd} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item static void {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+close\+\_\+ofd} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item static int {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+fd} (const struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item static void {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+read} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item static int {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+write} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item static int {\bfseries \+\_\+setsockopt\+\_\+nosigpipe} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item static void {\bfseries stream\+\_\+cli\+\_\+handle\+\_\+connecting} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int res) \item static int {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+fd\+\_\+cb} (struct osmo\+\_\+fd $\ast$ofd, unsigned int what) \item static void {\bfseries cli\+\_\+timer\+\_\+cb} (void $\ast$data) \item struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$ \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+create} (void $\ast$ctx) \begin{DoxyCompactList}\small\item\em Create an Osmocom stream client. \end{DoxyCompactList}\item static void {\bfseries stream\+\_\+cli\+\_\+iofd\+\_\+read\+\_\+cb} (struct osmo\+\_\+io\+\_\+fd $\ast$iofd, int res, struct msgb $\ast$msg) \item static void {\bfseries stream\+\_\+cli\+\_\+iofd\+\_\+write\+\_\+cb} (struct osmo\+\_\+io\+\_\+fd $\ast$iofd, int res, struct msgb $\ast$msg) \item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+name} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, const char $\ast$name) \begin{DoxyCompactList}\small\item\em Set a name on the cli object (used during logging) \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+addr} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the remote address to which we connect. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+addrs} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, const char $\ast$$\ast$addr, size\+\_\+t addrcnt) \begin{DoxyCompactList}\small\item\em Set the remote address set to which we connect. Useful for protocols allowing connecting to more than one address (such as SCTP) \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+port} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the remote port number to which we connect. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+local\+\_\+port} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, uint16\+\_\+t port) \begin{DoxyCompactList}\small\item\em Set the local port number for the socket (to be bound to) \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+local\+\_\+addr} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, const char $\ast$addr) \begin{DoxyCompactList}\small\item\em Set the local address for the socket (to be bound to) \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+local\+\_\+addrs} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, const char $\ast$$\ast$addr, size\+\_\+t addrcnt) \begin{DoxyCompactList}\small\item\em Set the local address set to which we connect. Useful for protocols allowing bind to more than one address (such as SCTP) \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+proto} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, uint16\+\_\+t proto) \begin{DoxyCompactList}\small\item\em Set the protocol for the stream client socket. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+type} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int type) \begin{DoxyCompactList}\small\item\em Set the socket type for the stream server link. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+domain} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int domain) \begin{DoxyCompactList}\small\item\em Set the socket type for the stream server link. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+reconnect\+\_\+timeout} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int timeout) \begin{DoxyCompactList}\small\item\em Set the reconnect time of the stream client socket. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+data} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, void $\ast$data) \begin{DoxyCompactList}\small\item\em Set application private data of the stream client socket. \end{DoxyCompactList}\item void $\ast$ \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+get\+\_\+data} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Get application private data of the stream client socket. \end{DoxyCompactList}\item char $\ast$ \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+get\+\_\+sockname} (const struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Get the stream client socket description. \end{DoxyCompactList}\item struct osmo\+\_\+fd $\ast$ \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+get\+\_\+ofd} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Get Osmocom File Descriptor of the stream client socket. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+connect\+\_\+cb} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int($\ast$connect\+\_\+cb)(struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli)) \begin{DoxyCompactList}\small\item\em Set the call-\/back function called on connect of the stream client socket. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+disconnect\+\_\+cb} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int($\ast$disconnect\+\_\+cb)(struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli)) \begin{DoxyCompactList}\small\item\em Set the call-\/back function called on disconnect of the stream client socket. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+read\+\_\+cb} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int($\ast$read\+\_\+cb)(struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli)) \begin{DoxyCompactList}\small\item\em Set the call-\/back function called to read from the stream client socket This function will configure \doxyref{osmo\+\_\+stream\+\_\+cli}{p.}{structosmo__stream__cli} to use osmo\+\_\+ofd internally. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+read\+\_\+cb2} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int($\ast$read\+\_\+cb)(struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, struct msgb $\ast$msg)) \begin{DoxyCompactList}\small\item\em Set the call-\/back function called to read from the stream client socket This function will configure \doxyref{osmo\+\_\+stream\+\_\+cli}{p.}{structosmo__stream__cli} to use osmo\+\_\+iofd internally. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+destroy} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Destroy a Osmocom stream client (includes close) \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+open2} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, int reconnect) \begin{DoxyCompactList}\small\item\em DEPRECATED\+: use \doxyref{osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+reconnect\+\_\+timeout()}{p.}{group__stream_gade74792afe35f31dd2584c888db3dd62} or \doxyref{osmo\+\_\+stream\+\_\+cli\+\_\+reconnect()}{p.}{group__stream_ga11d2615f6197f33073ba7245e5ba95ee} instead! Open connection of an Osmocom stream client. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+nodelay} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, bool nodelay) \begin{DoxyCompactList}\small\item\em Set the NODELAY socket option to avoid Nagle-\/like behavior Setting this to nodelay=true will automatically set the NODELAY socket option on any socket established via \doxyref{osmo\+\_\+stream\+\_\+cli\+\_\+open}{p.}{group__stream_ga86b4b9c8e563f8426d3cdae803e3ec38} or any re-\/connect. You have to set this {\itshape before} opening the socket. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+open} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \begin{DoxyCompactList}\small\item\em Open connection of an Osmocom stream client By default the client will automatically reconnect after default timeout. To disable this, use \doxyref{osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+reconnect\+\_\+timeout()}{p.}{group__stream_gade74792afe35f31dd2584c888db3dd62} before calling this function. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+send} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, struct msgb $\ast$msg) \begin{DoxyCompactList}\small\item\em Enqueue data to be sent via an Osmocom stream client. \end{DoxyCompactList}\item int \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+recv} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, struct msgb $\ast$msg) \begin{DoxyCompactList}\small\item\em Receive data via an Osmocom stream client. \end{DoxyCompactList}\item void {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+clear\+\_\+tx\+\_\+queue} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli) \item int {\bfseries osmo\+\_\+stream\+\_\+cli\+\_\+set\+\_\+param} (struct \textbf{ osmo\+\_\+stream\+\_\+cli} $\ast$cli, enum osmo\+\_\+stream\+\_\+cli\+\_\+param par, void $\ast$val, size\+\_\+t val\+\_\+len) \end{DoxyCompactItemize} \doxysubsection*{Variables} \begin{DoxyCompactItemize} \item static const struct value\+\_\+string \textbf{ stream\+\_\+cli\+\_\+state\+\_\+names} [$\,$] \item static struct osmo\+\_\+io\+\_\+ops \textbf{ osmo\+\_\+stream\+\_\+cli\+\_\+ioops} \end{DoxyCompactItemize} \doxysubsection{Detailed Description} Osmocom stream socket helpers (client side)