libosmo-netif  1.2.0.4-dcae
Osmocom network interface library
stream.h
1 #pragma once
2 
3 #include <stdbool.h>
4 #include <stdint.h>
5 
6 #include <osmocom/core/msgb.h>
7 
13 #define msgb_sctp_ppid(msg) (msg)->cb[3]
14 
15 #define msgb_sctp_stream(msg) (msg)->cb[4]
16 
19 
22 
23 void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay);
24 void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr);
25 int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt);
26 void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port);
27 void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto);
28 int osmo_stream_srv_link_set_type(struct osmo_stream_srv_link *link, int type);
29 int osmo_stream_srv_link_set_domain(struct osmo_stream_srv_link *link, int domain);
30 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));
31 void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data);
34 struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link);
35 
38 
41 struct osmo_stream_srv;
42 
43 struct osmo_stream_srv *osmo_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);
44 void *osmo_stream_srv_get_data(struct osmo_stream_srv *conn);
46 struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv);
47 void osmo_stream_srv_destroy(struct osmo_stream_srv *conn);
48 
50 void osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data);
51 
52 void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg);
53 int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg);
54 
56 struct osmo_stream_cli;
57 
58 void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay);
59 void osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr);
60 int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
61 void osmo_stream_cli_set_port(struct osmo_stream_cli *cli, uint16_t port);
62 int osmo_stream_cli_set_type(struct osmo_stream_cli *cli, int type);
63 int osmo_stream_cli_set_domain(struct osmo_stream_cli *cli, int domain);
64 void osmo_stream_cli_set_proto(struct osmo_stream_cli *cli, uint16_t proto);
65 void osmo_stream_cli_set_local_addr(struct osmo_stream_cli *cli, const char *addr);
66 int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
67 void osmo_stream_cli_set_local_port(struct osmo_stream_cli *cli, uint16_t port);
68 void osmo_stream_cli_set_data(struct osmo_stream_cli *cli, void *data);
69 void osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout);
70 void *osmo_stream_cli_get_data(struct osmo_stream_cli *cli);
71 char *osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli);
72 struct osmo_fd *osmo_stream_cli_get_ofd(struct osmo_stream_cli *cli);
73 void osmo_stream_cli_set_connect_cb(struct osmo_stream_cli *cli, int (*connect_cb)(struct osmo_stream_cli *cli));
74 void osmo_stream_cli_set_disconnect_cb(struct osmo_stream_cli *cli, int (*disconnect_cb)(struct osmo_stream_cli *cli));
75 void osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, int (*read_cb)(struct osmo_stream_cli *cli));
78 
79 struct osmo_stream_cli *osmo_stream_cli_create(void *ctx);
81 
82 int osmo_stream_cli_open(struct osmo_stream_cli *cli);
83 int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) \
84  OSMO_DEPRECATED("Use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead");
85 void osmo_stream_cli_close(struct osmo_stream_cli *cli);
86 
87 void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg);
88 int osmo_stream_cli_recv(struct osmo_stream_cli *conn, struct msgb *msg);
89 
osmo_stream_cli_set_connect_cb
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.
Definition: stream.c:685
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.
Definition: stream.c:496
osmo_stream_cli_set_disconnect_cb
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.
Definition: stream.c:694
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.
Definition: stream.c:588
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.
Definition: stream.c:1134
osmo_stream_srv_get_data
void * osmo_stream_srv_get_data(struct osmo_stream_srv *conn)
Get application private data of the stream server.
Definition: stream.c:1412
osmo_stream_cli_recv
int osmo_stream_cli_recv(struct osmo_stream_cli *conn, struct msgb *msg)
Receive data via an Osmocom stream client.
Definition: stream.c:883
osmo_stream_srv
Definition: stream.c:1261
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.
Definition: stream.c:1070
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.
Definition: stream.c:676
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.
Definition: stream.c:655
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 ...
Definition: stream.c:1394
osmo_stream_srv_get_ofd
struct osmo_fd * osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv)
Get Osmocom File Descriptor of the stream server.
Definition: stream.c:1421
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,...
Definition: stream.c:1250
osmo_stream_srv_link_set_accept_cb
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.
Definition: stream.c:1179
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.
Definition: stream.c:531
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 conf...
Definition: stream.c:1198
osmo_stream_cli_reconnect
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 un...
Definition: stream.c:277
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.
Definition: stream.c:599
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.
Definition: stream.c:1095
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.
Definition: stream.c:1143
osmo_stream_cli_create
struct osmo_stream_cli * osmo_stream_cli_create(void *ctx)
Create an Osmocom stream client.
Definition: stream.c:468
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.
Definition: stream.c:1453
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 addre...
Definition: stream.c:1047
osmo_stream_cli_get_sockname
char * osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli)
Get the stream client socket description.
Definition: stream.c:663
osmo_stream_srv_create
struct osmo_stream_srv * osmo_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.
Definition: stream.c:1361
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.
Definition: stream.c:618
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 ...
Definition: stream.c:798
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.
Definition: stream.c:1035
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.
Definition: stream.c:296
osmo_stream_cli_close
void osmo_stream_cli_close(struct osmo_stream_cli *cli)
Close an Osmocom Stream Client.
Definition: stream.c:305
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 automati...
Definition: stream.c:1023
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 lo...
Definition: stream.c:1440
osmo_stream_cli_open2
int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) OSMO_DEPRECATED("Use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead")
DEPRECATED: use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead!...
Definition: stream.c:726
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 ad...
Definition: stream.c:564
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.
Definition: stream.c:1082
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 automati...
Definition: stream.c:785
osmo_stream_cli_set_read_cb
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.
Definition: stream.c:704
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.
Definition: stream.c:871
osmo_stream_srv_recv
int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg)
Receive data via Osmocom stream server.
Definition: stream.c:1521
osmo_stream_cli
Definition: stream.c:248
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.
Definition: stream.c:1188
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)
Definition: stream.c:542
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.
Definition: stream.c:1151
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.
Definition: stream.c:647
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.
Definition: stream.c:1171
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 indivi...
Definition: stream.c:1000
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.
Definition: stream.c:1429
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.
Definition: stream.c:638
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...
Definition: stream.c:507
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)
Definition: stream.c:553
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.
Definition: stream.c:1403
osmo_stream_cli_destroy
void osmo_stream_cli_destroy(struct osmo_stream_cli *cli)
Destroy a Osmocom stream client (includes close)
Definition: stream.c:712
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.
Definition: stream.c:1114