libosmo-netif
1.4.0.19-26cd.202401052026
Osmocom network interface library
|
Osmocom stream socket helpers (client side) More...
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/fcntl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/select.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/osmo_io.h>
#include <osmocom/core/panic.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/socket.h>
#include <osmocom/netif/stream.h>
#include <osmocom/netif/stream_private.h>
#include "config.h"
#include <osmocom/netif/sctp.h>
Data Structures | |
struct | osmo_stream_cli |
Macros | |
#define | LOGSCLI(cli, level, fmt, args...) |
#define | OSMO_STREAM_CLI_F_RECONF (1 << 0) |
#define | OSMO_STREAM_CLI_F_NODELAY (1 << 1) |
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 | |
void | osmo_stream_cli_close (struct osmo_stream_cli *cli) |
Close an Osmocom Stream Client. 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... | |
static void | osmo_stream_cli_close_iofd (struct osmo_stream_cli *cli) |
static void | osmo_stream_cli_close_ofd (struct osmo_stream_cli *cli) |
int | osmo_stream_cli_get_fd (const struct osmo_stream_cli *cli) |
Get file descriptor of the stream client socket. More... | |
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 void | stream_cli_handle_connecting (struct osmo_stream_cli *cli, int res) |
static int | osmo_stream_cli_fd_cb (struct osmo_fd *ofd, unsigned int what) |
static void | cli_timer_cb (void *data) |
struct osmo_stream_cli * | osmo_stream_cli_create (void *ctx) |
Create an Osmocom stream client. More... | |
static void | stream_cli_iofd_read_cb (struct osmo_io_fd *iofd, int res, struct msgb *msg) |
static void | stream_cli_iofd_write_cb (struct osmo_io_fd *iofd, int res, struct msgb *msg) |
void | osmo_stream_cli_set_name (struct osmo_stream_cli *cli, const char *name) |
Set a name on the cli object (used during logging) 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... | |
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_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_proto (struct osmo_stream_cli *cli, uint16_t proto) |
Set the protocol for the stream client socket. More... | |
static void | configure_cli_segmentation_cb (struct osmo_io_fd *iofd, int(*segmentation_cb)(struct msgb *msg)) |
void | osmo_stream_cli_set_segmentation_cb (struct osmo_stream_cli *cli, int(*segmentation_cb)(struct msgb *msg)) |
Set the segmentation callback for the client. 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_reconnect_timeout (struct osmo_stream_cli *cli, int timeout) |
Set the reconnect time of the stream client socket. 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_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 This function will configure osmo_stream_cli to use osmo_ofd internally. More... | |
void | osmo_stream_cli_set_read_cb2 (struct osmo_stream_cli *cli, int(*read_cb)(struct osmo_stream_cli *cli, struct msgb *msg)) |
Set the call-back function called to read from the stream client socket This function will configure osmo_stream_cli to use osmo_iofd internally. More... | |
void | osmo_stream_cli_destroy (struct osmo_stream_cli *cli) |
Destroy a Osmocom stream client (includes close) 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_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... | |
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... | |
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) |
int | osmo_stream_cli_set_param (struct osmo_stream_cli *cli, enum osmo_stream_cli_param par, void *val, size_t val_len) |
Variables | |
static const struct value_string | stream_cli_state_names [] |
static struct osmo_io_ops | osmo_stream_cli_ioops |
Osmocom stream socket helpers (client side)