libosmo-netif  1.2.0.67-9ee4
Osmocom network interface library
Osmocom Stream Socket

Files

file  stream.c
 Osmocom stream socket helpers.
 

Data Structures

struct  osmo_stream_cli
 
struct  osmo_stream_srv_link
 
struct  osmo_stream_srv
 

Macros

#define OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION   0x80 /* sctp_recvmsg() flags=MSG_NOTIFICATION, msgb_data() contains "union sctp_notification*" */
 Access SCTP flags from the msgb control buffer.
 
#define msgb_sctp_msg_flags(msg)   (msg)->cb[2]
 
#define msgb_sctp_ppid(msg)   (msg)->cb[3]
 Access the SCTP PPID from the msgb control buffer.
 
#define msgb_sctp_stream(msg)   (msg)->cb[4]
 Access the SCTP Stream ID from the msgb control buffer.
 
#define MSG_NOSIGNAL   0
 
#define OSMO_STREAM_CLI_F_RECONF   (1 << 0)
 
#define OSMO_STREAM_CLI_F_NODELAY   (1 << 1)
 
#define OSMO_STREAM_MAX_ADDRS   OSMO_SOCK_MAX_ADDRS
 
#define OSMO_STREAM_SRV_F_RECONF   (1 << 0)
 
#define OSMO_STREAM_SRV_F_NODELAY   (1 << 1)
 
#define OSMO_STREAM_SRV_F_FLUSH_DESTROY   (1 << 0)
 

Enumerations

enum  osmo_stream_cli_state {
  STREAM_CLI_STATE_CLOSED, STREAM_CLI_STATE_WAIT_RECONNECT, STREAM_CLI_STATE_CONNECTING, STREAM_CLI_STATE_CONNECTED,
  STREAM_CLI_STATE_MAX
}
 

Functions

struct osmo_stream_srv_linkosmo_stream_srv_link_create (void *ctx)
 Create an Osmocom Stream Server Link A Stream Server Link is the listen()+accept() "parent" to individual Stream Servers. More...
 
void osmo_stream_srv_link_destroy (struct osmo_stream_srv_link *link)
 Destroy the stream server link. Closes + Releases Memory. More...
 
void osmo_stream_srv_link_set_nodelay (struct osmo_stream_srv_link *link, bool nodelay)
 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 this server link, before calling the accept_cb() More...
 
void osmo_stream_srv_link_set_addr (struct osmo_stream_srv_link *link, const char *addr)
 Set the local address to which we bind. More...
 
int osmo_stream_srv_link_set_addrs (struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt)
 Set the local address set to which we bind. Useful for protocols allowing bind on more than one address (such as SCTP) More...
 
void osmo_stream_srv_link_set_port (struct osmo_stream_srv_link *link, uint16_t port)
 Set the local port number to which we bind. More...
 
void osmo_stream_srv_link_set_proto (struct osmo_stream_srv_link *link, uint16_t proto)
 Set the protocol for the stream server link. More...
 
int osmo_stream_srv_link_set_type (struct osmo_stream_srv_link *link, int type)
 Set the socket type for the stream server link. More...
 
int osmo_stream_srv_link_set_domain (struct osmo_stream_srv_link *link, int domain)
 Set the socket type for the stream server link. More...
 
void osmo_stream_srv_link_set_accept_cb (struct osmo_stream_srv_link *link, int(*accept_cb)(struct osmo_stream_srv_link *link, int fd))
 Set the accept() call-back of the stream server link. More...
 
void osmo_stream_srv_link_set_data (struct osmo_stream_srv_link *link, void *data)
 Set application private data of the stream server link. More...
 
void * osmo_stream_srv_link_get_data (struct osmo_stream_srv_link *link)
 Get application private data of the stream server link. More...
 
char * osmo_stream_srv_link_get_sockname (const struct osmo_stream_srv_link *link)
 Get description of the stream server link e. g. 127.0.0.1:1234. More...
 
struct osmo_fd * osmo_stream_srv_link_get_ofd (struct osmo_stream_srv_link *link)
 Get Osmocom File Descriptor of the stream server link. More...
 
int osmo_stream_srv_link_open (struct osmo_stream_srv_link *link)
 Open the stream server link. This actually initializes the underlying socket and binds it to the configured ip/port. More...
 
void osmo_stream_srv_link_close (struct osmo_stream_srv_link *link)
 Close the stream server link and unregister from select loop Does not destroy the server link, merely closes it! More...
 
struct osmo_stream_srvosmo_stream_srv_create (void *ctx, struct osmo_stream_srv_link *link, int fd, int(*cb)(struct osmo_stream_srv *conn), int(*closed_cb)(struct osmo_stream_srv *conn), void *data)
 Create a Stream Server inside the specified link. More...
 
void * osmo_stream_srv_get_data (struct osmo_stream_srv *conn)
 Get application private data of the stream server. More...
 
struct osmo_stream_srv_linkosmo_stream_srv_get_master (struct osmo_stream_srv *conn)
 Get the master (Link) from a Stream Server. More...
 
struct osmo_fd * osmo_stream_srv_get_ofd (struct osmo_stream_srv *conn)
 Get Osmocom File Descriptor of the stream server. More...
 
void osmo_stream_srv_destroy (struct osmo_stream_srv *conn)
 Destroy given Stream Server This function closes the Stream Server socket, unregisters from select loop, invokes the connection's closed_cb() callback to allow API users to clean up any associated state they have for this connection, and then de-allocates associated memory. More...
 
void osmo_stream_srv_set_flush_and_destroy (struct osmo_stream_srv *conn)
 Prepare to send out all pending messages on the connection's Tx queue and then automatically destroy the stream with osmo_stream_srv_destroy(). This function disables queuing of new messages on the connection and also disables reception of new messages on the connection. More...
 
void osmo_stream_srv_set_data (struct osmo_stream_srv *conn, void *data)
 Set application private data of the stream server. More...
 
void osmo_stream_srv_send (struct osmo_stream_srv *conn, struct msgb *msg)
 Enqueue data to be sent via an Osmocom stream server. More...
 
int osmo_stream_srv_recv (struct osmo_stream_srv *conn, struct msgb *msg)
 Receive data via Osmocom stream server. More...
 
void osmo_stream_srv_clear_tx_queue (struct osmo_stream_srv *conn)
 
void osmo_stream_cli_set_nodelay (struct osmo_stream_cli *cli, bool nodelay)
 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 osmo_stream_cli_open or any re-connect. You have to set this before opening the socket. More...
 
void osmo_stream_cli_set_addr (struct osmo_stream_cli *cli, const char *addr)
 Set the remote address to which we connect. More...
 
int osmo_stream_cli_set_addrs (struct osmo_stream_cli *cli, const char **addr, size_t addrcnt)
 Set the remote address set to which we connect. Useful for protocols allowing connecting to more than one address (such as SCTP) More...
 
void osmo_stream_cli_set_port (struct osmo_stream_cli *cli, uint16_t port)
 Set the remote port number to which we connect. More...
 
int osmo_stream_cli_set_type (struct osmo_stream_cli *cli, int type)
 Set the socket type for the stream server link. More...
 
int osmo_stream_cli_set_domain (struct osmo_stream_cli *cli, int domain)
 Set the socket type for the stream server link. More...
 
void osmo_stream_cli_set_proto (struct osmo_stream_cli *cli, uint16_t proto)
 Set the protocol for the stream client socket. More...
 
void osmo_stream_cli_set_local_addr (struct osmo_stream_cli *cli, const char *addr)
 Set the local address for the socket (to be bound to) More...
 
int osmo_stream_cli_set_local_addrs (struct osmo_stream_cli *cli, const char **addr, size_t addrcnt)
 Set the local address set to which we connect. Useful for protocols allowing bind to more than one address (such as SCTP) More...
 
void osmo_stream_cli_set_local_port (struct osmo_stream_cli *cli, uint16_t port)
 Set the local port number for the socket (to be bound to) More...
 
void osmo_stream_cli_set_data (struct osmo_stream_cli *cli, void *data)
 Set application private data of the stream client socket. More...
 
void osmo_stream_cli_set_reconnect_timeout (struct osmo_stream_cli *cli, int timeout)
 Set the reconnect time of the stream client socket. More...
 
void * osmo_stream_cli_get_data (struct osmo_stream_cli *cli)
 Get application private data of the stream client socket. More...
 
char * osmo_stream_cli_get_sockname (const struct osmo_stream_cli *cli)
 Get the stream client socket description. More...
 
struct osmo_fd * osmo_stream_cli_get_ofd (struct osmo_stream_cli *cli)
 Get Osmocom File Descriptor of the stream client socket. More...
 
void osmo_stream_cli_set_connect_cb (struct osmo_stream_cli *cli, int(*connect_cb)(struct osmo_stream_cli *cli))
 Set the call-back function called on connect of the stream client socket. More...
 
void osmo_stream_cli_set_disconnect_cb (struct osmo_stream_cli *cli, int(*disconnect_cb)(struct osmo_stream_cli *cli))
 Set the call-back function called on disconnect of the stream client socket. More...
 
void osmo_stream_cli_set_read_cb (struct osmo_stream_cli *cli, int(*read_cb)(struct osmo_stream_cli *cli))
 Set the call-back function called to read from the stream client socket. More...
 
void osmo_stream_cli_reconnect (struct osmo_stream_cli *cli)
 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 osmo_stream_cli_set_reconnect_timeout() call), we close any existing connection (if any) and schedule a re-connect timer.
 
bool osmo_stream_cli_is_connected (struct osmo_stream_cli *cli)
 Check if Osmocom Stream Client is in connected state. More...
 
struct osmo_stream_cliosmo_stream_cli_create (void *ctx)
 Create an Osmocom stream client. More...
 
void osmo_stream_cli_destroy (struct osmo_stream_cli *cli)
 Destroy a Osmocom stream client (includes close) More...
 
int osmo_stream_cli_open (struct osmo_stream_cli *cli)
 Open connection of an Osmocom stream client By default the client will automatically reconnect after default timeout. To disable this, use osmo_stream_cli_set_reconnect_timeout() before calling this function. More...
 
int osmo_stream_cli_open2 (struct osmo_stream_cli *cli, int reconnect)
 DEPRECATED: use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead! Open connection of an Osmocom stream client. More...
 
void osmo_stream_cli_close (struct osmo_stream_cli *cli)
 Close an Osmocom Stream Client. More...
 
void osmo_stream_cli_send (struct osmo_stream_cli *cli, struct msgb *msg)
 Enqueue data to be sent via an Osmocom stream client. More...
 
int osmo_stream_cli_recv (struct osmo_stream_cli *cli, struct msgb *msg)
 Receive data via an Osmocom stream client. More...
 
void osmo_stream_cli_clear_tx_queue (struct osmo_stream_cli *cli)
 
static int byte_nonzero (const uint8_t *u8, unsigned int offset, unsigned int u8_size)
 
static int determine_sctp_sockopt_event_subscribe_size (void)
 
static int sctp_setsockopt_events_linux_workaround (int fd, const struct sctp_event_subscribe *event)
 
static int sctp_sock_activate_events (int fd)
 
static int setsockopt_nodelay (int fd, int proto, int on)
 
static void osmo_stream_cli_read (struct osmo_stream_cli *cli)
 
static int osmo_stream_cli_write (struct osmo_stream_cli *cli)
 
static int _setsockopt_nosigpipe (struct osmo_stream_cli *cli)
 
static int osmo_stream_cli_fd_cb (struct osmo_fd *ofd, unsigned int what)
 
static void cli_timer_cb (void *data)
 
static int osmo_stream_srv_fd_cb (struct osmo_fd *ofd, unsigned int what)
 
static int osmo_stream_srv_read (struct osmo_stream_srv *conn)
 
static void osmo_stream_srv_write (struct osmo_stream_srv *conn)
 
static int osmo_stream_srv_cb (struct osmo_fd *ofd, unsigned int what)
 
static int _sctp_recvmsg_wrapper (int fd, struct msgb *msg)
 

Variables

static unsigned int sctp_sockopt_event_subscribe_size = 0
 
static const struct value_string stream_cli_state_names []
 

Detailed Description

This code is intended to abstract any use of stream-type sockets, such as TCP and SCTP. It offers both server and client side implementations, fully integrated with the libosmocore select loop abstraction.

Function Documentation

◆ osmo_stream_cli_close()

void osmo_stream_cli_close ( struct osmo_stream_cli cli)

Close an Osmocom Stream Client.

Parameters
[in]cliOsmocom Stream Client to be closed We unregister the socket fd from the osmocom select() loop abstraction and close the socket

Referenced by osmo_stream_cli_destroy(), and osmo_stream_cli_reconnect().

◆ osmo_stream_cli_create()

struct osmo_stream_cli * osmo_stream_cli_create ( void *  ctx)

Create an Osmocom stream client.

Parameters
[in]ctxtalloc context from which to allocate memory This function allocates a new osmo_stream_cli and initializes it with default values (5s reconnect timer, TCP protocol)
Returns
allocated stream client, or NULL in case of error

◆ osmo_stream_cli_destroy()

void osmo_stream_cli_destroy ( struct osmo_stream_cli cli)

Destroy a Osmocom stream client (includes close)

Parameters
[in]cliStream Client to destroy

References osmo_stream_cli_close().

◆ osmo_stream_cli_get_data()

void * osmo_stream_cli_get_data ( struct osmo_stream_cli cli)

Get application private data of the stream client socket.

Parameters
[in]cliStream Client to modify
Returns
Application private data, as set by osmo_stream_cli_set_data()

◆ osmo_stream_cli_get_ofd()

struct osmo_fd * osmo_stream_cli_get_ofd ( struct osmo_stream_cli cli)

Get Osmocom File Descriptor of the stream client socket.

Parameters
[in]cliStream Client to modify
Returns
Pointer to osmo_fd

◆ osmo_stream_cli_get_sockname()

char * osmo_stream_cli_get_sockname ( const struct osmo_stream_cli cli)

Get the stream client socket description.

Parameters
[in]cliStream Client to examine
Returns
Socket description or NULL in case of error

◆ osmo_stream_cli_is_connected()

bool osmo_stream_cli_is_connected ( struct osmo_stream_cli cli)

Check if Osmocom Stream Client is in connected state.

Parameters
[in]cliOsmocom Stream Client
Returns
true if connected, false otherwise

◆ osmo_stream_cli_open()

int osmo_stream_cli_open ( struct osmo_stream_cli cli)

Open connection of an Osmocom stream client By default the client will automatically reconnect after default timeout. To disable this, use osmo_stream_cli_set_reconnect_timeout() before calling this function.

Parameters
[in]cliStream Client to connect
Returns
negative on error, 0 on success

◆ osmo_stream_cli_open2()

int osmo_stream_cli_open2 ( struct osmo_stream_cli cli,
int  reconnect 
)

DEPRECATED: use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead! Open connection of an Osmocom stream client.

Parameters
[in]cliStream Client to connect
[in]reconect1 if we should not automatically reconnect
Returns
negative on error, 0 on success

◆ osmo_stream_cli_recv()

int osmo_stream_cli_recv ( struct osmo_stream_cli cli,
struct msgb *  msg 
)

Receive data via an Osmocom stream client.

Parameters
[in]cliStream Client through which we want to send
msgpre-allocate message buffer to which received data is appended
Returns
number of bytes read; <=0 in case of error

◆ osmo_stream_cli_send()

void osmo_stream_cli_send ( struct osmo_stream_cli cli,
struct msgb *  msg 
)

Enqueue data to be sent via an Osmocom stream client.

Parameters
[in]cliStream Client through which we want to send
[in]msgMessage buffer to enqueue in transmit queue

◆ osmo_stream_cli_set_addr()

void osmo_stream_cli_set_addr ( struct osmo_stream_cli cli,
const char *  addr 
)

Set the remote address to which we connect.

Parameters
[in]cliStream Client to modify
[in]addrRemote IP address

References osmo_stream_cli_set_addrs().

◆ osmo_stream_cli_set_addrs()

int osmo_stream_cli_set_addrs ( struct osmo_stream_cli cli,
const char **  addr,
size_t  addrcnt 
)

Set the remote address set to which we connect. Useful for protocols allowing connecting to more than one address (such as SCTP)

Parameters
[in]cliStream Client to modify
[in]addrRemote IP address set
Returns
negative on error, 0 on success

Referenced by osmo_stream_cli_set_addr().

◆ osmo_stream_cli_set_connect_cb()

void osmo_stream_cli_set_connect_cb ( struct osmo_stream_cli cli,
int(*)(struct osmo_stream_cli *cli)  connect_cb 
)

Set the call-back function called on connect of the stream client socket.

Parameters
[in]cliStream Client to modify
[in]connect_cbCall-back function to be called upon connect

◆ osmo_stream_cli_set_data()

void osmo_stream_cli_set_data ( struct osmo_stream_cli cli,
void *  data 
)

Set application private data of the stream client socket.

Parameters
[in]cliStream Client to modify
[in]dataUser-specific data (available in call-back functions)

◆ osmo_stream_cli_set_disconnect_cb()

void osmo_stream_cli_set_disconnect_cb ( struct osmo_stream_cli cli,
int(*)(struct osmo_stream_cli *cli)  disconnect_cb 
)

Set the call-back function called on disconnect of the stream client socket.

Parameters
[in]cliStream Client to modify
[in]disconnect_cbCall-back function to be called upon disconnect

◆ osmo_stream_cli_set_domain()

int osmo_stream_cli_set_domain ( struct osmo_stream_cli cli,
int  domain 
)

Set the socket type for the stream server link.

Parameters
[in]cliStream Client to modify
[in]typeSocket Domain (like AF_UNSPEC (default for IP), AF_UNIX, AF_INET, ...)
Returns
zero on success, negative on error.

◆ osmo_stream_cli_set_local_addr()

void osmo_stream_cli_set_local_addr ( struct osmo_stream_cli cli,
const char *  addr 
)

Set the local address for the socket (to be bound to)

Parameters
[in]cliStream Client to modify
[in]portLocal host name

References osmo_stream_cli_set_local_addrs().

◆ osmo_stream_cli_set_local_addrs()

int osmo_stream_cli_set_local_addrs ( struct osmo_stream_cli cli,
const char **  addr,
size_t  addrcnt 
)

Set the local address set to which we connect. Useful for protocols allowing bind to more than one address (such as SCTP)

Parameters
[in]cliStream Client to modify
[in]addrLocal IP address set
Returns
negative on error, 0 on success

Referenced by osmo_stream_cli_set_local_addr().

◆ osmo_stream_cli_set_local_port()

void osmo_stream_cli_set_local_port ( struct osmo_stream_cli cli,
uint16_t  port 
)

Set the local port number for the socket (to be bound to)

Parameters
[in]cliStream Client to modify
[in]portLocal port number

◆ osmo_stream_cli_set_nodelay()

void osmo_stream_cli_set_nodelay ( struct osmo_stream_cli cli,
bool  nodelay 
)

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 osmo_stream_cli_open or any re-connect. You have to set this before opening the socket.

Parameters
[in]cliStream client whose sockets are to be configured
[in]nodelaywhether to set (true) NODELAY before connect()

◆ osmo_stream_cli_set_port()

void osmo_stream_cli_set_port ( struct osmo_stream_cli cli,
uint16_t  port 
)

Set the remote port number to which we connect.

Parameters
[in]cliStream Client to modify
[in]portRemote port number

◆ osmo_stream_cli_set_proto()

void osmo_stream_cli_set_proto ( struct osmo_stream_cli cli,
uint16_t  proto 
)

Set the protocol for the stream client socket.

Parameters
[in]cliStream Client to modify
[in]protoProtocol (like IPPROTO_TCP (default), IPPROTO_SCTP, ...)

◆ osmo_stream_cli_set_read_cb()

void osmo_stream_cli_set_read_cb ( struct osmo_stream_cli cli,
int(*)(struct osmo_stream_cli *cli)  read_cb 
)

Set the call-back function called to read from the stream client socket.

Parameters
[in]cliStream Client to modify
[in]read_cbCall-back function to be called when we want to read

◆ osmo_stream_cli_set_reconnect_timeout()

void osmo_stream_cli_set_reconnect_timeout ( struct osmo_stream_cli cli,
int  timeout 
)

Set the reconnect time of the stream client socket.

Parameters
[in]cliStream Client to modify
[in]timeoutRe-connect timeout in seconds or negative value to disable auto-reconnection

◆ osmo_stream_cli_set_type()

int osmo_stream_cli_set_type ( struct osmo_stream_cli cli,
int  type 
)

Set the socket type for the stream server link.

Parameters
[in]cliStream Client to modify
[in]typeSocket Type (like SOCK_STREAM (default), SOCK_SEQPACKET, ...)
Returns
zero on success, negative on error.

◆ osmo_stream_srv_create()

struct osmo_stream_srv * osmo_stream_srv_create ( void *  ctx,
struct osmo_stream_srv_link link,
int  fd,
int(*)(struct osmo_stream_srv *conn)  cb,
int(*)(struct osmo_stream_srv *conn)  closed_cb,
void *  data 
)

Create a Stream Server inside the specified link.

Parameters
[in]ctxtalloc allocation context from which to allocate
[in]linkStream Server Link to which we belong
Returns
Stream Server in case of success; NULL on error

◆ osmo_stream_srv_destroy()

void osmo_stream_srv_destroy ( struct osmo_stream_srv conn)

Destroy given Stream Server This function closes the Stream Server socket, unregisters from select loop, invokes the connection's closed_cb() callback to allow API users to clean up any associated state they have for this connection, and then de-allocates associated memory.

Parameters
[in]connStream Server to be destroyed

◆ osmo_stream_srv_get_data()

void * osmo_stream_srv_get_data ( struct osmo_stream_srv conn)

Get application private data of the stream server.

Parameters
[in]connStream Server
Returns
Application private data, as set by osmo_stream_srv_set_data()

◆ osmo_stream_srv_get_master()

struct osmo_stream_srv_link * osmo_stream_srv_get_master ( struct osmo_stream_srv conn)

Get the master (Link) from a Stream Server.

Parameters
[in]connStream Server of which we want to know the Link
Returns
Link through which the given Stream Server is established

◆ osmo_stream_srv_get_ofd()

struct osmo_fd * osmo_stream_srv_get_ofd ( struct osmo_stream_srv conn)

Get Osmocom File Descriptor of the stream server.

Parameters
[in]connStream Server
Returns
Pointer to osmo_fd

◆ osmo_stream_srv_link_close()

void osmo_stream_srv_link_close ( struct osmo_stream_srv_link link)

Close the stream server link and unregister from select loop Does not destroy the server link, merely closes it!

Parameters
[in]linkStream Server Link to close

Referenced by osmo_stream_srv_link_destroy().

◆ osmo_stream_srv_link_create()

struct osmo_stream_srv_link * osmo_stream_srv_link_create ( void *  ctx)

Create an Osmocom Stream Server Link A Stream Server Link is the listen()+accept() "parent" to individual Stream Servers.

Parameters
[in]ctxtalloc allocation context
Returns
Stream Server Link with default values (TCP)

◆ osmo_stream_srv_link_destroy()

void osmo_stream_srv_link_destroy ( struct osmo_stream_srv_link link)

Destroy the stream server link. Closes + Releases Memory.

Parameters
[in]linkStream Server Link

References osmo_stream_srv_link_close().

◆ osmo_stream_srv_link_get_data()

void * osmo_stream_srv_link_get_data ( struct osmo_stream_srv_link link)

Get application private data of the stream server link.

Parameters
[in]linkStream Server Link to modify
Returns
Application private data, as set by osmo_stream_cli_set_data()

◆ osmo_stream_srv_link_get_ofd()

struct osmo_fd * osmo_stream_srv_link_get_ofd ( struct osmo_stream_srv_link link)

Get Osmocom File Descriptor of the stream server link.

Parameters
[in]linkStream Server Link
Returns
Pointer to osmo_fd

◆ osmo_stream_srv_link_get_sockname()

char * osmo_stream_srv_link_get_sockname ( const struct osmo_stream_srv_link link)

Get description of the stream server link e. g. 127.0.0.1:1234.

Parameters
[in]linkStream Server Link to examine
Returns
Link description or NULL in case of error

◆ osmo_stream_srv_link_open()

int osmo_stream_srv_link_open ( struct osmo_stream_srv_link link)

Open the stream server link. This actually initializes the underlying socket and binds it to the configured ip/port.

Parameters
[in]linkStream Server Link to open
Returns
negative on error, 0 on success

◆ osmo_stream_srv_link_set_accept_cb()

void osmo_stream_srv_link_set_accept_cb ( struct osmo_stream_srv_link link,
int(*)(struct osmo_stream_srv_link *link, int fd)  accept_cb 
)

Set the accept() call-back of the stream server link.

Parameters
[in]linkStream Server Link
[in]accept_cbCall-back function executed upon accept()

◆ osmo_stream_srv_link_set_addr()

void osmo_stream_srv_link_set_addr ( struct osmo_stream_srv_link link,
const char *  addr 
)

Set the local address to which we bind.

Parameters
[in]linkStream Server Link to modify
[in]addrLocal IP address

References osmo_stream_srv_link_set_addrs().

◆ osmo_stream_srv_link_set_addrs()

int osmo_stream_srv_link_set_addrs ( struct osmo_stream_srv_link link,
const char **  addr,
size_t  addrcnt 
)

Set the local address set to which we bind. Useful for protocols allowing bind on more than one address (such as SCTP)

Parameters
[in]linkStream Server Link to modify
[in]addrLocal IP address
Returns
negative on error, 0 on success

Referenced by osmo_stream_srv_link_set_addr().

◆ osmo_stream_srv_link_set_data()

void osmo_stream_srv_link_set_data ( struct osmo_stream_srv_link link,
void *  data 
)

Set application private data of the stream server link.

Parameters
[in]linkStream Server Link to modify
[in]dataUser-specific data (available in call-back functions)

◆ osmo_stream_srv_link_set_domain()

int osmo_stream_srv_link_set_domain ( struct osmo_stream_srv_link link,
int  domain 
)

Set the socket type for the stream server link.

Parameters
[in]linkStream Server Link to modify
[in]typeSocket Domain (like AF_UNSPEC (default for IP), AF_UNIX, AF_INET, ...)
Returns
zero on success, negative on error.

◆ osmo_stream_srv_link_set_nodelay()

void osmo_stream_srv_link_set_nodelay ( struct osmo_stream_srv_link link,
bool  nodelay 
)

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 this server link, before calling the accept_cb()

Parameters
[in]linkserver link whose sockets are to be configured
[in]nodelaywhether to set (true) NODELAY after accept

◆ osmo_stream_srv_link_set_port()

void osmo_stream_srv_link_set_port ( struct osmo_stream_srv_link link,
uint16_t  port 
)

Set the local port number to which we bind.

Parameters
[in]linkStream Server Link to modify
[in]portLocal port number

◆ osmo_stream_srv_link_set_proto()

void osmo_stream_srv_link_set_proto ( struct osmo_stream_srv_link link,
uint16_t  proto 
)

Set the protocol for the stream server link.

Parameters
[in]linkStream Server Link to modify
[in]protoProtocol (like IPPROTO_TCP (default), IPPROTO_SCTP, ...)

◆ osmo_stream_srv_link_set_type()

int osmo_stream_srv_link_set_type ( struct osmo_stream_srv_link link,
int  type 
)

Set the socket type for the stream server link.

Parameters
[in]linkStream Server Link to modify
[in]typeSocket Type (like SOCK_STREAM (default), SOCK_SEQPACKET, ...)
Returns
zero on success, negative on error.

◆ osmo_stream_srv_recv()

int osmo_stream_srv_recv ( struct osmo_stream_srv conn,
struct msgb *  msg 
)

Receive data via Osmocom stream server.

Parameters
[in]connStream Server from which to receive
msgpre-allocate message buffer to which received data is appended
Returns
number of bytes read, negative on error.

If conn is an SCTP connection, additional specific considerations shall be taken:

  • msg->cb is always filled with SCTP ppid, and SCTP stream values, see msgb_sctp_*() APIs.
  • If an SCTP notification was received when reading from the SCTP socket, msgb_sctp_msg_flags(msg) will contain bit flag OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION set, and the msgb will contain a "union sctp_notification" instead of user data. In this case the return code will be either 0 (if conn is considered dead after the notification) or -EAGAIN (if conn is considered still alive after the notification) resembling the standard recv() API.

◆ osmo_stream_srv_send()

void osmo_stream_srv_send ( struct osmo_stream_srv conn,
struct msgb *  msg 
)

Enqueue data to be sent via an Osmocom stream server.

Parameters
[in]connStream Server through which we want to send
[in]msgMessage buffer to enqueue in transmit queue

◆ osmo_stream_srv_set_data()

void osmo_stream_srv_set_data ( struct osmo_stream_srv conn,
void *  data 
)

Set application private data of the stream server.

Parameters
[in]connStream Server to modify
[in]dataUser-specific data (available in call-back functions)

◆ osmo_stream_srv_set_flush_and_destroy()

void osmo_stream_srv_set_flush_and_destroy ( struct osmo_stream_srv conn)

Prepare to send out all pending messages on the connection's Tx queue and then automatically destroy the stream with osmo_stream_srv_destroy(). This function disables queuing of new messages on the connection and also disables reception of new messages on the connection.

Parameters
[in]connStream Server to modify

Variable Documentation

◆ stream_cli_state_names

const struct value_string stream_cli_state_names[]
static
Initial value:
= {
{ STREAM_CLI_STATE_CLOSED, "CLOSED" },
{ STREAM_CLI_STATE_WAIT_RECONNECT, "WAIT_RECONNECT" },
{ STREAM_CLI_STATE_CONNECTING, "CONNECTING" },
{ STREAM_CLI_STATE_CONNECTED, "CONNECTED" },
{ 0, NULL }
}