aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2011-10-09 18:00:53 +0200
committerPablo Neira Ayuso <pablo@gnumonks.org>2011-10-09 18:00:53 +0200
commitad2eca4768dbf939a7ff0a00d7ae466f27a41413 (patch)
treefea49fd6886a26c85fce5b43a757036455e6f898
parent06a1557578417091e7b0f6c33a3cf3dcec0a5520 (diff)
stream: add osmo_ prefix to all functions
Modify examples as well to use the new API.
-rw-r--r--examples/stream-client.c34
-rw-r--r--examples/stream-server.c43
-rw-r--r--include/osmocom/netif/stream.h46
-rw-r--r--src/stream.c152
4 files changed, 142 insertions, 133 deletions
diff --git a/examples/stream-client.c b/examples/stream-client.c
index 441e681..7f95800 100644
--- a/examples/stream-client.c
+++ b/examples/stream-client.c
@@ -14,7 +14,7 @@
#define DSTREAMTEST 0
-struct log_info_cat stream_client_test_cat[] = {
+struct log_info_cat osmo_stream_client_test_cat[] = {
[DSTREAMTEST] = {
.name = "DSTREAMTEST",
.description = "STREAMCLIENT-mode test",
@@ -23,13 +23,13 @@ struct log_info_cat stream_client_test_cat[] = {
},
};
-const struct log_info stream_client_test_log_info = {
+const struct log_info osmo_stream_client_test_log_info = {
.filter_fn = NULL,
- .cat = stream_client_test_cat,
- .num_cat = ARRAY_SIZE(stream_client_test_cat),
+ .cat = osmo_stream_client_test_cat,
+ .num_cat = ARRAY_SIZE(osmo_stream_client_test_cat),
};
-static struct stream_client_conn *conn;
+static struct osmo_stream_client_conn *conn;
void sighandler(int foo)
{
@@ -37,13 +37,13 @@ void sighandler(int foo)
exit(EXIT_SUCCESS);
}
-static int connect_cb(struct stream_client_conn *conn)
+static int connect_cb(struct osmo_stream_client_conn *conn)
{
LOGP(DSTREAMTEST, LOGL_NOTICE, "connected\n");
return 0;
}
-static int read_cb(struct stream_client_conn *conn, struct msgb *msg)
+static int read_cb(struct osmo_stream_client_conn *conn, struct msgb *msg)
{
LOGP(DSTREAMTEST, LOGL_NOTICE, "received message from stream\n");
return 0;
@@ -64,13 +64,13 @@ static int kbd_cb(struct osmo_fd *fd, unsigned int what)
msg = msgb_alloc(1024, "STREAMCLIENT/test");
if (msg == NULL) {
- LOGP(DSTREAMTEST, LOGL_ERROR, "stream_client: cannot allocate message\n");
+ LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
return 0;
}
ptr = msgb_put(msg, strlen(buf));
memcpy(ptr, buf, ret);
- stream_client_conn_send(conn, msg);
+ osmo_stream_client_conn_send(conn, msg);
LOGP(DSTREAMTEST, LOGL_NOTICE, "message of %d bytes sent\n", msg->len);
@@ -81,26 +81,26 @@ int main(void)
{
struct osmo_fd *kbd_ofd;
- tall_test = talloc_named_const(NULL, 1, "stream_client_test");
+ tall_test = talloc_named_const(NULL, 1, "osmo_stream_client_test");
- osmo_init_logging(&stream_client_test_log_info);
+ osmo_init_logging(&osmo_stream_client_test_log_info);
log_set_log_level(osmo_stderr_target, 1);
/*
* initialize stream client.
*/
- conn = stream_client_conn_create(tall_test);
+ conn = osmo_stream_client_conn_create(tall_test);
if (conn == NULL) {
fprintf(stderr, "cannot create client\n");
exit(EXIT_FAILURE);
}
- stream_client_conn_set_addr(conn, "127.0.0.1");
- stream_client_conn_set_port(conn, 10000);
- stream_client_conn_set_connect_cb(conn, connect_cb);
- stream_client_conn_set_read_cb(conn, read_cb);
+ osmo_stream_client_conn_set_addr(conn, "127.0.0.1");
+ osmo_stream_client_conn_set_port(conn, 10000);
+ osmo_stream_client_conn_set_connect_cb(conn, connect_cb);
+ osmo_stream_client_conn_set_read_cb(conn, read_cb);
- if (stream_client_conn_open(conn) < 0) {
+ if (osmo_stream_client_conn_open(conn) < 0) {
fprintf(stderr, "cannot open client\n");
exit(EXIT_FAILURE);
}
diff --git a/examples/stream-server.c b/examples/stream-server.c
index 2a49052..d8eb380 100644
--- a/examples/stream-server.c
+++ b/examples/stream-server.c
@@ -16,7 +16,7 @@ static void *tall_test;
#define DSTREAMTEST 0
-struct log_info_cat stream_server_test_cat[] = {
+struct log_info_cat osmo_stream_server_test_cat[] = {
[DSTREAMTEST] = {
.name = "DSTREAMTEST",
.description = "STREAMSERVER-mode test",
@@ -25,14 +25,14 @@ struct log_info_cat stream_server_test_cat[] = {
},
};
-const struct log_info stream_server_test_log_info = {
+const struct log_info osmo_stream_server_test_log_info = {
.filter_fn = NULL,
- .cat = stream_server_test_cat,
- .num_cat = ARRAY_SIZE(stream_server_test_cat),
+ .cat = osmo_stream_server_test_cat,
+ .num_cat = ARRAY_SIZE(osmo_stream_server_test_cat),
};
-static struct stream_server_link *server;
-static struct stream_server_conn *conn;
+static struct osmo_stream_server_link *server;
+static struct osmo_stream_server_conn *conn;
void sighandler(int foo)
@@ -41,19 +41,19 @@ void sighandler(int foo)
exit(EXIT_SUCCESS);
}
-int read_cb(struct stream_server_conn *conn, struct msgb *msg)
+int read_cb(struct osmo_stream_server_conn *conn, struct msgb *msg)
{
LOGP(DSTREAMTEST, LOGL_NOTICE, "received message from stream\n");
return 0;
}
-static int close_cb(struct stream_server_conn *dummy)
+static int close_cb(struct osmo_stream_server_conn *dummy)
{
conn = NULL;
return 0;
}
-static int accept_cb(struct stream_server_link *server, int fd)
+static int accept_cb(struct osmo_stream_server_link *server, int fd)
{
if (conn != NULL) {
LOGP(DSTREAMTEST, LOGL_ERROR, "Sorry, this example only "
@@ -61,10 +61,11 @@ static int accept_cb(struct stream_server_link *server, int fd)
return -1;
}
- conn = stream_server_conn_create(tall_test, server, fd, read_cb,
+ conn = osmo_stream_server_conn_create(tall_test, server, fd, read_cb,
close_cb, NULL);
if (conn == NULL) {
- LOGP(DSTREAMTEST, LOGL_ERROR, "error in stream_server_receive\n");
+ LOGP(DSTREAMTEST, LOGL_ERROR,
+ "error while creating connection\n");
return -1;
}
@@ -87,14 +88,14 @@ static int kbd_cb(struct osmo_fd *fd, unsigned int what)
return 0;
}
- msg = msgb_alloc(1024, "stream_server_test");
+ msg = msgb_alloc(1024, "osmo_stream_server_test");
if (msg == NULL) {
- LOGP(DSTREAMTEST, LOGL_ERROR, "stream_server: cannot allocate message\n");
+ LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
return 0;
}
ptr = msgb_put(msg, strlen(buf));
memcpy(ptr, buf, strlen(buf));
- stream_server_conn_send(conn, msg);
+ osmo_stream_server_conn_send(conn, msg);
LOGP(DSTREAMTEST, LOGL_NOTICE, "message of %d bytes sent\n", msg->len);
@@ -105,25 +106,25 @@ int main(void)
{
struct osmo_fd *kbd_ofd;
- tall_test = talloc_named_const(NULL, 1, "stream_server_test");
+ tall_test = talloc_named_const(NULL, 1, "osmo_stream_server_test");
- osmo_init_logging(&stream_server_test_log_info);
+ osmo_init_logging(&osmo_stream_server_test_log_info);
log_set_log_level(osmo_stderr_target, 1);
/*
* initialize stream server.
*/
- server = stream_server_link_create(tall_test);
+ server = osmo_stream_server_link_create(tall_test);
if (server == NULL) {
fprintf(stderr, "cannot create client\n");
exit(EXIT_FAILURE);
}
- stream_server_link_set_addr(server, "127.0.0.1");
- stream_server_link_set_port(server, 10000);
- stream_server_link_set_accept_cb(server, accept_cb);
+ osmo_stream_server_link_set_addr(server, "127.0.0.1");
+ osmo_stream_server_link_set_port(server, 10000);
+ osmo_stream_server_link_set_accept_cb(server, accept_cb);
- if (stream_server_link_open(server) < 0) {
+ if (osmo_stream_server_link_open(server) < 0) {
fprintf(stderr, "cannot open client\n");
exit(EXIT_FAILURE);
}
diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index de65176..ceace28 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -1,39 +1,39 @@
#ifndef _OSMO_STREAM_H_
#define _OSMO_STREAM_H_
-struct stream_server_link;
+struct osmo_stream_server_link;
-struct stream_server_link *stream_server_link_create(void *ctx);
-void stream_server_link_destroy(struct stream_server_link *link);
+struct osmo_stream_server_link *osmo_stream_server_link_create(void *ctx);
+void osmo_stream_server_link_destroy(struct osmo_stream_server_link *link);
-void stream_server_link_set_addr(struct stream_server_link *link, const char *addr);
-void stream_server_link_set_port(struct stream_server_link *link, uint16_t port);
-void stream_server_link_set_accept_cb(struct stream_server_link *link, int (*accept_cb)(struct stream_server_link *link, int fd));
+void osmo_stream_server_link_set_addr(struct osmo_stream_server_link *link, const char *addr);
+void osmo_stream_server_link_set_port(struct osmo_stream_server_link *link, uint16_t port);
+void osmo_stream_server_link_set_accept_cb(struct osmo_stream_server_link *link, int (*accept_cb)(struct osmo_stream_server_link *link, int fd));
-int stream_server_link_open(struct stream_server_link *link);
-void stream_server_link_close(struct stream_server_link *link);
+int osmo_stream_server_link_open(struct osmo_stream_server_link *link);
+void osmo_stream_server_link_close(struct osmo_stream_server_link *link);
-struct stream_server_conn;
+struct osmo_stream_server_conn;
-struct stream_server_conn *stream_server_conn_create(void *ctx, struct stream_server_link *link, int fd, int (*cb)(struct stream_server_conn *conn, struct msgb *msg), int (*closed_cb)(struct stream_server_conn *conn), void *data);
-void stream_server_conn_destroy(struct stream_server_conn *conn);
+struct osmo_stream_server_conn *osmo_stream_server_conn_create(void *ctx, struct osmo_stream_server_link *link, int fd, int (*cb)(struct osmo_stream_server_conn *conn, struct msgb *msg), int (*closed_cb)(struct osmo_stream_server_conn *conn), void *data);
+void osmo_stream_server_conn_destroy(struct osmo_stream_server_conn *conn);
-void stream_server_conn_send(struct stream_server_conn *conn, struct msgb *msg);
+void osmo_stream_server_conn_send(struct osmo_stream_server_conn *conn, struct msgb *msg);
-struct stream_client_conn;
+struct osmo_stream_client_conn;
-void stream_client_conn_set_addr(struct stream_client_conn *link, const char *addr);
-void stream_client_conn_set_port(struct stream_client_conn *link, uint16_t port);
-void stream_client_conn_set_data(struct stream_client_conn *link, void *data);
-void stream_client_conn_set_connect_cb(struct stream_client_conn *link, int (*connect_cb)(struct stream_client_conn *link));
-void stream_client_conn_set_read_cb(struct stream_client_conn *link, int (*read_cb)(struct stream_client_conn *link, struct msgb *msgb));
+void osmo_stream_client_conn_set_addr(struct osmo_stream_client_conn *link, const char *addr);
+void osmo_stream_client_conn_set_port(struct osmo_stream_client_conn *link, uint16_t port);
+void osmo_stream_client_conn_set_data(struct osmo_stream_client_conn *link, void *data);
+void osmo_stream_client_conn_set_connect_cb(struct osmo_stream_client_conn *link, int (*connect_cb)(struct osmo_stream_client_conn *link));
+void osmo_stream_client_conn_set_read_cb(struct osmo_stream_client_conn *link, int (*read_cb)(struct osmo_stream_client_conn *link, struct msgb *msgb));
-struct stream_client_conn *stream_client_conn_create(void *ctx);
-void stream_client_conn_destroy(struct stream_client_conn *link);
+struct osmo_stream_client_conn *osmo_stream_client_conn_create(void *ctx);
+void osmo_stream_client_conn_destroy(struct osmo_stream_client_conn *link);
-int stream_client_conn_open(struct stream_client_conn *link);
-void stream_client_conn_close(struct stream_client_conn *link);
+int osmo_stream_client_conn_open(struct osmo_stream_client_conn *link);
+void osmo_stream_client_conn_close(struct osmo_stream_client_conn *link);
-void stream_client_conn_send(struct stream_client_conn *link, struct msgb *msg);
+void osmo_stream_client_conn_send(struct osmo_stream_client_conn *link, struct msgb *msg);
#endif
diff --git a/src/stream.c b/src/stream.c
index 9447a64..11b05ec 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -23,44 +23,44 @@
* Client side.
*/
-enum stream_client_conn_state {
+enum osmo_stream_client_conn_state {
STREAM_CLIENT_LINK_STATE_NONE = 0,
STREAM_CLIENT_LINK_STATE_CONNECTING = 1,
STREAM_CLIENT_LINK_STATE_CONNECTED = 2,
STREAM_CLIENT_LINK_STATE_MAX
};
-struct stream_client_conn {
+struct osmo_stream_client_conn {
struct osmo_fd ofd;
struct llist_head tx_queue;
struct osmo_timer_list timer;
- enum stream_client_conn_state state;
+ enum osmo_stream_client_conn_state state;
const char *addr;
uint16_t port;
- int (*connect_cb)(struct stream_client_conn *link);
- int (*read_cb)(struct stream_client_conn *link, struct msgb *msg);
- int (*write_cb)(struct stream_client_conn *link);
+ int (*connect_cb)(struct osmo_stream_client_conn *link);
+ int (*read_cb)(struct osmo_stream_client_conn *link, struct msgb *msg);
+ int (*write_cb)(struct osmo_stream_client_conn *link);
void *data;
};
-void stream_client_conn_close(struct stream_client_conn *link);
+void osmo_stream_client_conn_close(struct osmo_stream_client_conn *link);
-static void stream_client_retry(struct stream_client_conn *link)
+static void osmo_stream_client_retry(struct osmo_stream_client_conn *link)
{
LOGP(DLINP, LOGL_DEBUG, "connection closed\n");
- stream_client_conn_close(link);
+ osmo_stream_client_conn_close(link);
LOGP(DLINP, LOGL_DEBUG, "retrying in 5 seconds...\n");
osmo_timer_schedule(&link->timer, 5, 0);
link->state = STREAM_CLIENT_LINK_STATE_CONNECTING;
}
-void stream_client_conn_close(struct stream_client_conn *link)
+void osmo_stream_client_conn_close(struct osmo_stream_client_conn *link)
{
osmo_fd_unregister(&link->ofd);
close(link->ofd.fd);
}
-static void stream_client_read(struct stream_client_conn *link)
+static void osmo_stream_client_read(struct osmo_stream_client_conn *link)
{
struct msgb *msg;
int ret;
@@ -77,11 +77,11 @@ static void stream_client_read(struct stream_client_conn *link)
if (errno == EPIPE || errno == ECONNRESET) {
LOGP(DLINP, LOGL_ERROR, "lost connection with server\n");
}
- stream_client_retry(link);
+ osmo_stream_client_retry(link);
return;
} else if (ret == 0) {
LOGP(DLINP, LOGL_ERROR, "connection closed with server\n");
- stream_client_retry(link);
+ osmo_stream_client_retry(link);
return;
}
msgb_put(msg, ret);
@@ -89,7 +89,7 @@ static void stream_client_read(struct stream_client_conn *link)
link->read_cb(link, msg);
}
-static int stream_client_write(struct stream_client_conn *link)
+static int osmo_stream_client_write(struct osmo_stream_client_conn *link)
{
struct msgb *msg;
struct llist_head *lh;
@@ -113,7 +113,7 @@ static int stream_client_write(struct stream_client_conn *link)
ret = send(link->ofd.fd, msg->data, msg->len, 0);
if (ret < 0) {
if (errno == EPIPE || errno == ENOTCONN) {
- stream_client_retry(link);
+ osmo_stream_client_retry(link);
}
LOGP(DLINP, LOGL_ERROR, "error to send\n");
}
@@ -121,9 +121,9 @@ static int stream_client_write(struct stream_client_conn *link)
return 0;
}
-static int stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what)
+static int osmo_stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what)
{
- struct stream_client_conn *link = ofd->data;
+ struct osmo_stream_client_conn *link = ofd->data;
int error, ret;
socklen_t len = sizeof(error);
@@ -131,7 +131,7 @@ static int stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what)
case STREAM_CLIENT_LINK_STATE_CONNECTING:
ret = getsockopt(ofd->fd, SOL_SOCKET, SO_ERROR, &error, &len);
if (ret >= 0 && error > 0) {
- stream_client_retry(link);
+ osmo_stream_client_retry(link);
return 0;
}
ofd->when &= ~BSC_FD_WRITE;
@@ -143,11 +143,11 @@ static int stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what)
case STREAM_CLIENT_LINK_STATE_CONNECTED:
if (what & BSC_FD_READ) {
LOGP(DLINP, LOGL_DEBUG, "connected read\n");
- stream_client_read(link);
+ osmo_stream_client_read(link);
}
if (what & BSC_FD_WRITE) {
LOGP(DLINP, LOGL_DEBUG, "connected write\n");
- stream_client_write(link);
+ osmo_stream_client_write(link);
}
break;
default:
@@ -158,17 +158,17 @@ static int stream_client_fd_cb(struct osmo_fd *ofd, unsigned int what)
static void link_timer_cb(void *data);
-struct stream_client_conn *stream_client_conn_create(void *ctx)
+struct osmo_stream_client_conn *osmo_stream_client_conn_create(void *ctx)
{
- struct stream_client_conn *link;
+ struct osmo_stream_client_conn *link;
- link = talloc_zero(ctx, struct stream_client_conn);
+ link = talloc_zero(ctx, struct osmo_stream_client_conn);
if (!link)
return NULL;
link->ofd.when |= BSC_FD_READ | BSC_FD_WRITE;
link->ofd.priv_nr = 0; /* XXX */
- link->ofd.cb = stream_client_fd_cb;
+ link->ofd.cb = osmo_stream_client_fd_cb;
link->ofd.data = link;
link->state = STREAM_CLIENT_LINK_STATE_CONNECTING;
link->timer.cb = link_timer_cb;
@@ -179,43 +179,46 @@ struct stream_client_conn *stream_client_conn_create(void *ctx)
}
void
-stream_client_conn_set_addr(struct stream_client_conn *link, const char *addr)
+osmo_stream_client_conn_set_addr(struct osmo_stream_client_conn *link,
+ const char *addr)
{
link->addr = talloc_strdup(link, addr);
}
void
-stream_client_conn_set_port(struct stream_client_conn *link, uint16_t port)
+osmo_stream_client_conn_set_port(struct osmo_stream_client_conn *link,
+ uint16_t port)
{
link->port = port;
}
void
-stream_client_conn_set_data(struct stream_client_conn *link, void *data)
+osmo_stream_client_conn_set_data(struct osmo_stream_client_conn *link,
+ void *data)
{
link->data = data;
}
void
-stream_client_conn_set_connect_cb(struct stream_client_conn *link,
- int (*connect_cb)(struct stream_client_conn *link))
+osmo_stream_client_conn_set_connect_cb(struct osmo_stream_client_conn *link,
+ int (*connect_cb)(struct osmo_stream_client_conn *link))
{
link->connect_cb = connect_cb;
}
void
-stream_client_conn_set_read_cb(struct stream_client_conn *link,
- int (*read_cb)(struct stream_client_conn *link, struct msgb *msgb))
+osmo_stream_client_conn_set_read_cb(struct osmo_stream_client_conn *link,
+ int (*read_cb)(struct osmo_stream_client_conn *link, struct msgb *msgb))
{
link->read_cb = read_cb;
}
-void stream_client_conn_destroy(struct stream_client_conn *link)
+void osmo_stream_client_conn_destroy(struct osmo_stream_client_conn *link)
{
talloc_free(link);
}
-int stream_client_conn_open(struct stream_client_conn *link)
+int osmo_stream_client_conn_open(struct osmo_stream_client_conn *link)
{
int ret;
@@ -236,20 +239,21 @@ int stream_client_conn_open(struct stream_client_conn *link)
static void link_timer_cb(void *data)
{
- struct stream_client_conn *link = data;
+ struct osmo_stream_client_conn *link = data;
LOGP(DLINP, LOGL_DEBUG, "reconnecting.\n");
switch(link->state) {
case STREAM_CLIENT_LINK_STATE_CONNECTING:
- stream_client_conn_open(link);
+ osmo_stream_client_conn_open(link);
break;
default:
break;
}
}
-void stream_client_conn_send(struct stream_client_conn *link, struct msgb *msg)
+void osmo_stream_client_conn_send(struct osmo_stream_client_conn *link,
+ struct msgb *msg)
{
msgb_enqueue(&link->tx_queue, msg);
link->ofd.when |= BSC_FD_WRITE;
@@ -259,20 +263,20 @@ void stream_client_conn_send(struct stream_client_conn *link, struct msgb *msg)
* Server side.
*/
-struct stream_server_link {
+struct osmo_stream_server_link {
struct osmo_fd ofd;
const char *addr;
uint16_t port;
- int (*accept_cb)(struct stream_server_link *link, int fd);
+ int (*accept_cb)(struct osmo_stream_server_link *link, int fd);
void *data;
};
-static int stream_server_fd_cb(struct osmo_fd *ofd, unsigned int what)
+static int osmo_stream_server_fd_cb(struct osmo_fd *ofd, unsigned int what)
{
int ret;
struct sockaddr_in sa;
socklen_t sa_len = sizeof(sa);
- struct stream_server_link *link = ofd->data;
+ struct osmo_stream_server_link *link = ofd->data;
ret = accept(ofd->fd, (struct sockaddr *)&sa, &sa_len);
if (ret < 0) {
@@ -289,44 +293,46 @@ static int stream_server_fd_cb(struct osmo_fd *ofd, unsigned int what)
return 0;
}
-struct stream_server_link *stream_server_link_create(void *ctx)
+struct osmo_stream_server_link *osmo_stream_server_link_create(void *ctx)
{
- struct stream_server_link *link;
+ struct osmo_stream_server_link *link;
- link = talloc_zero(ctx, struct stream_server_link);
+ link = talloc_zero(ctx, struct osmo_stream_server_link);
if (!link)
return NULL;
link->ofd.when |= BSC_FD_READ | BSC_FD_WRITE;
- link->ofd.cb = stream_server_fd_cb;
+ link->ofd.cb = osmo_stream_server_fd_cb;
link->ofd.data = link;
return link;
}
-void stream_server_link_set_addr(struct stream_server_link *link, const char *addr)
+void osmo_stream_server_link_set_addr(struct osmo_stream_server_link *link,
+ const char *addr)
{
link->addr = talloc_strdup(link, addr);
}
-void stream_server_link_set_port(struct stream_server_link *link, uint16_t port)
+void osmo_stream_server_link_set_port(struct osmo_stream_server_link *link,
+ uint16_t port)
{
link->port = port;
}
-void stream_server_link_set_accept_cb(struct stream_server_link *link,
- int (*accept_cb)(struct stream_server_link *link, int fd))
+void osmo_stream_server_link_set_accept_cb(struct osmo_stream_server_link *link,
+ int (*accept_cb)(struct osmo_stream_server_link *link, int fd))
{
link->accept_cb = accept_cb;
}
-void stream_server_link_destroy(struct stream_server_link *link)
+void osmo_stream_server_link_destroy(struct osmo_stream_server_link *link)
{
talloc_free(link);
}
-int stream_server_link_open(struct stream_server_link *link)
+int osmo_stream_server_link_open(struct osmo_stream_server_link *link)
{
int ret;
@@ -343,22 +349,22 @@ int stream_server_link_open(struct stream_server_link *link)
return 0;
}
-void stream_server_link_close(struct stream_server_link *link)
+void osmo_stream_server_link_close(struct osmo_stream_server_link *link)
{
osmo_fd_unregister(&link->ofd);
close(link->ofd.fd);
}
-struct stream_server_conn {
- struct stream_server_link *server;
+struct osmo_stream_server_conn {
+ struct osmo_stream_server_link *server;
struct osmo_fd ofd;
struct llist_head tx_queue;
- int (*closed_cb)(struct stream_server_conn *peer);
- int (*cb)(struct stream_server_conn *peer, struct msgb *msg);
+ int (*closed_cb)(struct osmo_stream_server_conn *peer);
+ int (*cb)(struct osmo_stream_server_conn *peer, struct msgb *msg);
void *data;
};
-static void stream_server_conn_read(struct stream_server_conn *conn)
+static void osmo_stream_server_conn_read(struct osmo_stream_server_conn *conn)
{
struct msgb *msg;
int ret;
@@ -375,11 +381,11 @@ static void stream_server_conn_read(struct stream_server_conn *conn)
if (errno == EPIPE || errno == ECONNRESET) {
LOGP(DLINP, LOGL_ERROR, "lost connection with server\n");
}
- stream_server_conn_destroy(conn);
+ osmo_stream_server_conn_destroy(conn);
return;
} else if (ret == 0) {
LOGP(DLINP, LOGL_ERROR, "connection closed with server\n");
- stream_server_conn_destroy(conn);
+ osmo_stream_server_conn_destroy(conn);
return;
}
msgb_put(msg, ret);
@@ -390,7 +396,7 @@ static void stream_server_conn_read(struct stream_server_conn *conn)
return;
}
-static void stream_server_conn_write(struct stream_server_conn *conn)
+static void osmo_stream_server_conn_write(struct osmo_stream_server_conn *conn)
{
struct msgb *msg;
struct llist_head *lh;
@@ -413,27 +419,28 @@ static void stream_server_conn_write(struct stream_server_conn *conn)
msgb_free(msg);
}
-static int stream_server_conn_cb(struct osmo_fd *ofd, unsigned int what)
+static int osmo_stream_server_conn_cb(struct osmo_fd *ofd, unsigned int what)
{
- struct stream_server_conn *conn = ofd->data;
+ struct osmo_stream_server_conn *conn = ofd->data;
LOGP(DLINP, LOGL_DEBUG, "connected read/write\n");
if (what & BSC_FD_READ)
- stream_server_conn_read(conn);
+ osmo_stream_server_conn_read(conn);
if (what & BSC_FD_WRITE)
- stream_server_conn_write(conn);
+ osmo_stream_server_conn_write(conn);
return 0;
}
-struct stream_server_conn *
-stream_server_conn_create(void *ctx, struct stream_server_link *link, int fd,
- int (*cb)(struct stream_server_conn *conn, struct msgb *msg),
- int (*closed_cb)(struct stream_server_conn *conn), void *data)
+struct osmo_stream_server_conn *
+osmo_stream_server_conn_create(void *ctx, struct osmo_stream_server_link *link,
+ int fd,
+ int (*cb)(struct osmo_stream_server_conn *conn, struct msgb *msg),
+ int (*closed_cb)(struct osmo_stream_server_conn *conn), void *data)
{
- struct stream_server_conn *conn;
+ struct osmo_stream_server_conn *conn;
- conn = talloc_zero(ctx, struct stream_server_conn);
+ conn = talloc_zero(ctx, struct osmo_stream_server_conn);
if (conn == NULL) {
LOGP(DLINP, LOGL_ERROR, "cannot allocate new peer in server, "
"reason=`%s'\n", strerror(errno));
@@ -442,7 +449,7 @@ stream_server_conn_create(void *ctx, struct stream_server_link *link, int fd,
conn->server = link;
conn->ofd.fd = fd;
conn->ofd.data = conn;
- conn->ofd.cb = stream_server_conn_cb;
+ conn->ofd.cb = osmo_stream_server_conn_cb;
conn->ofd.when = BSC_FD_READ;
conn->cb = cb;
conn->closed_cb = closed_cb;
@@ -457,7 +464,7 @@ stream_server_conn_create(void *ctx, struct stream_server_link *link, int fd,
return conn;
}
-void stream_server_conn_destroy(struct stream_server_conn *conn)
+void osmo_stream_server_conn_destroy(struct osmo_stream_server_conn *conn)
{
close(conn->ofd.fd);
osmo_fd_unregister(&conn->ofd);
@@ -466,7 +473,8 @@ void stream_server_conn_destroy(struct stream_server_conn *conn)
talloc_free(conn);
}
-void stream_server_conn_send(struct stream_server_conn *conn, struct msgb *msg)
+void osmo_stream_server_conn_send(struct osmo_stream_server_conn *conn,
+ struct msgb *msg)
{
msgb_enqueue(&conn->tx_queue, msg);
conn->ofd.when |= BSC_FD_WRITE;