aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2023-03-17 11:37:10 +0100
committerDaniel Willmann <dwillmann@sysmocom.de>2023-06-08 15:17:10 +0200
commit5faa542abd2a55292258a97c82a9b8c4b895dc35 (patch)
tree9ca5ec2364a82c283445dfafdbcb35133dfb0af9
parent9b6f691e84b4cfc8380eb0a14eb1eed7c125746f (diff)
examples: Use osmo_io in {ipa-,}stream-{client,server}daniel/osmo_io
-rw-r--r--examples/ipa-stream-client.c21
-rw-r--r--examples/ipa-stream-server.c23
-rw-r--r--examples/stream-client.c24
-rw-r--r--examples/stream-server.c27
4 files changed, 19 insertions, 76 deletions
diff --git a/examples/ipa-stream-client.c b/examples/ipa-stream-client.c
index 0c9c589..fc48a50 100644
--- a/examples/ipa-stream-client.c
+++ b/examples/ipa-stream-client.c
@@ -103,21 +103,10 @@ static int connect_cb(struct osmo_stream_cli *conn)
return 0;
}
-static int read_cb(struct osmo_stream_cli *conn)
+static int read_cb(struct osmo_stream_cli *conn, struct msgb *msg)
{
- struct msgb *msg;
+ LOGP(DIPATEST, LOGL_DEBUG, "received message from stream (len=%d)\n", msgb_length(msg));
- LOGP(DIPATEST, LOGL_DEBUG, "received message from stream\n");
-
- msg = osmo_ipa_msg_alloc(0);
- if (msg == NULL) {
- LOGP(DIPATEST, LOGL_ERROR, "cannot allocate message\n");
- return 0;
- }
- if (osmo_stream_cli_recv(conn, msg) <= 0) {
- LOGP(DIPATEST, LOGL_ERROR, "cannot receive message\n");
- return 0;
- }
if (osmo_ipa_process_msg(msg) < 0) {
LOGP(DIPATEST, LOGL_ERROR, "bad IPA message\n");
return 0;
@@ -169,13 +158,13 @@ int main(int argc, char *argv[])
tall_test = talloc_named_const(NULL, 1, "osmo_stream_client_test");
msgb_talloc_ctx_init(tall_test, 0);
osmo_init_logging2(tall_test, &osmo_stream_client_test_log_info);
- log_set_log_level(osmo_stderr_target, LOGL_NOTICE);
+ log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
/*
* initialize stream client.
*/
- conn = osmo_stream_cli_create(tall_test);
+ conn = osmo_stream_cli_create_iofd(tall_test, "ipa test client");
if (conn == NULL) {
fprintf(stderr, "cannot create client\n");
exit(EXIT_FAILURE);
@@ -184,7 +173,7 @@ int main(int argc, char *argv[])
osmo_stream_cli_set_port(conn, 10000);
osmo_stream_cli_set_connect_cb(conn, connect_cb);
osmo_stream_cli_set_disconnect_cb(conn, disconnect_cb);
- osmo_stream_cli_set_read_cb(conn, read_cb);
+ osmo_stream_cli_set_iofd_read_cb(conn, read_cb);
osmo_stream_cli_set_data(conn, &num_msgs);
osmo_stream_cli_set_nodelay(conn, true);
diff --git a/examples/ipa-stream-server.c b/examples/ipa-stream-server.c
index 1ca1aaf..9cc56db 100644
--- a/examples/ipa-stream-server.c
+++ b/examples/ipa-stream-server.c
@@ -47,23 +47,10 @@ void sighandler(int foo)
exit(EXIT_SUCCESS);
}
-int read_cb(struct osmo_stream_srv *conn)
+int read_cb(struct osmo_stream_srv *conn, struct msgb *msg)
{
- struct msgb *msg;
+ LOGP(DSTREAMTEST, LOGL_DEBUG, "received message from stream (len=%d)\n", msgb_length(msg));
- LOGP(DSTREAMTEST, LOGL_DEBUG, "received message from stream\n");
-
- msg = osmo_ipa_msg_alloc(0);
- if (msg == NULL) {
- LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
- return 0;
- }
- if (osmo_stream_srv_recv(conn, msg) <= 0) {
- LOGP(DSTREAMTEST, LOGL_ERROR, "cannot receive message\n");
- osmo_stream_srv_destroy(conn);
- msgb_free(msg);
- return -EBADF;
- }
if (osmo_ipa_process_msg(msg) < 0) {
LOGP(DSTREAMTEST, LOGL_ERROR, "Bad IPA message\n");
msgb_free(msg);
@@ -84,11 +71,11 @@ static int accept_cb(struct osmo_stream_srv_link *srv, int fd)
{
if (conn != NULL) {
LOGP(DSTREAMTEST, LOGL_ERROR, "Sorry, this example only "
- "support one client simultaneously\n");
+ "supports one client simultaneously\n");
return -1;
}
- conn = osmo_stream_srv_create(tall_test, srv, fd,
+ conn = osmo_stream_srv_create_iofd(tall_test, "srv link", srv, fd,
read_cb, close_cb, NULL);
if (conn == NULL) {
LOGP(DSTREAMTEST, LOGL_ERROR,
@@ -104,7 +91,7 @@ int main(void)
tall_test = talloc_named_const(NULL, 1, "osmo_stream_srv_test");
msgb_talloc_ctx_init(tall_test, 0);
osmo_init_logging2(tall_test, &osmo_stream_srv_test_log_info);
- log_set_log_level(osmo_stderr_target, LOGL_NOTICE);
+ log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
/*
* initialize stream srv.
diff --git a/examples/stream-client.c b/examples/stream-client.c
index 428402e..7b8e092 100644
--- a/examples/stream-client.c
+++ b/examples/stream-client.c
@@ -50,27 +50,11 @@ static int disconnect_cb(struct osmo_stream_cli *conn)
return 0;
}
-static int read_cb(struct osmo_stream_cli *conn)
+static int read_cb(struct osmo_stream_cli *conn, struct msgb* msg)
{
- int bytes;
- struct msgb *msg;
-
LOGP(DSTREAMTEST, LOGL_NOTICE, "receiving message from stream... ");
- msg = msgb_alloc(1024, "STREAMCLIENT/test");
- if (msg == NULL) {
- LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
- return 0;
- }
-
- bytes = osmo_stream_cli_recv(conn, msg);
-
- if (bytes < 0) {
- LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message\n");
- return 0;
- }
-
- LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d (%d) bytes: %s\n", bytes, msg->len, msgb_hexdump(msg));
+ LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d bytes: %s\n", msg->len, msgb_hexdump(msg));
msgb_free(msg);
return 0;
@@ -120,7 +104,7 @@ int main(void)
* initialize stream cli.
*/
- conn = osmo_stream_cli_create(tall_test);
+ conn = osmo_stream_cli_create_iofd(tall_test, "stream client");
if (conn == NULL) {
fprintf(stderr, "cannot create cli\n");
exit(EXIT_FAILURE);
@@ -129,7 +113,7 @@ int main(void)
osmo_stream_cli_set_port(conn, 10000);
osmo_stream_cli_set_connect_cb(conn, connect_cb);
osmo_stream_cli_set_disconnect_cb(conn, disconnect_cb);
- osmo_stream_cli_set_read_cb(conn, read_cb);
+ osmo_stream_cli_set_iofd_read_cb(conn, read_cb);
if (osmo_stream_cli_open(conn) < 0) {
fprintf(stderr, "cannot open cli\n");
diff --git a/examples/stream-server.c b/examples/stream-server.c
index e4ca480..f6edf42 100644
--- a/examples/stream-server.c
+++ b/examples/stream-server.c
@@ -42,29 +42,11 @@ void sighandler(int foo)
exit(EXIT_SUCCESS);
}
-int read_cb(struct osmo_stream_srv *conn)
+int read_cb(struct osmo_stream_srv *conn, struct msgb* msg)
{
- int bytes;
- struct msgb *msg;
-
LOGP(DSTREAMTEST, LOGL_NOTICE, "receiving message from stream... ");
- msg = msgb_alloc(1024, "STREAMSERVER/test");
- if (msg == NULL) {
- LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
- return 0;
- }
-
- bytes = osmo_stream_srv_recv(conn, msg);
-
- if (bytes <= 0) {
- if (bytes < 0)
- LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message: %s\n", strerror(-bytes));
- else
- LOGPC(DSTREAMTEST, LOGL_ERROR, "client closed connection\n");
- osmo_stream_srv_destroy(conn);
- } else
- LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d (%d) bytes: %s\n", bytes, msg->len, msgb_hexdump(msg));
+ LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d bytes: %s\n", msg->len, msgb_hexdump(msg));
msgb_free(msg);
return 0;
@@ -72,6 +54,7 @@ int read_cb(struct osmo_stream_srv *conn)
static int close_cb(struct osmo_stream_srv *dummy)
{
+ LOGPC(DSTREAMTEST, LOGL_ERROR, "client closed connection\n");
conn = NULL;
return 0;
}
@@ -86,8 +69,8 @@ static int accept_cb(struct osmo_stream_srv_link *srv, int fd)
return -1;
}
- conn = osmo_stream_srv_create(tall_test, srv, fd, read_cb,
- close_cb, NULL);
+ conn = osmo_stream_srv_create_iofd(tall_test, "stream server", srv, fd, read_cb,
+ close_cb, NULL);
if (conn == NULL) {
LOGP(DSTREAMTEST, LOGL_ERROR,
"error while creating connection\n");