diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/ipa-stream-client.c | 8 | ||||
-rw-r--r-- | examples/ipa-stream-server.c | 9 | ||||
-rw-r--r-- | examples/stream-client.c | 9 | ||||
-rw-r--r-- | examples/stream-server.c | 13 |
4 files changed, 35 insertions, 4 deletions
diff --git a/examples/ipa-stream-client.c b/examples/ipa-stream-client.c index 720fe66..b58370e 100644 --- a/examples/ipa-stream-client.c +++ b/examples/ipa-stream-client.c @@ -102,13 +102,19 @@ static int connect_cb(struct osmo_stream_cli *conn) return 0; } -static int read_cb(struct osmo_stream_cli *conn, struct msgb *msg) +static int read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg) { int num; struct msg_sent *cur, *tmp, *found = NULL; LOGP(DIPATEST, LOGL_DEBUG, "received message from stream (payload len=%d)\n", msgb_length(msg)); + if (res <= 0) { + LOGP(DIPATEST, LOGL_ERROR, "Event with no data! %d\n", res); + msgb_free(msg); + return 0; + } + if (osmo_ipa_process_msg(msg) < 0) { LOGP(DIPATEST, LOGL_ERROR, "bad IPA message\n"); msgb_free(msg); diff --git a/examples/ipa-stream-server.c b/examples/ipa-stream-server.c index 5317921..e87eab4 100644 --- a/examples/ipa-stream-server.c +++ b/examples/ipa-stream-server.c @@ -47,8 +47,15 @@ void sighandler(int foo) exit(EXIT_SUCCESS); } -int read_cb(struct osmo_stream_srv *conn, struct msgb *msg) +int read_cb(struct osmo_stream_srv *conn, int res, struct msgb *msg) { + if (res <= 0) { + LOGP(DSTREAMTEST, LOGL_ERROR, "cannot receive message (%d)\n", res); + msgb_free(msg); + osmo_stream_srv_destroy(conn); + return -EBADF; + } + LOGP(DSTREAMTEST, LOGL_DEBUG, "received message from stream (payload len=%d)\n", msgb_length(msg)); osmo_ipa_msg_push_headers(msg, osmo_ipa_msgb_cb_proto(msg), osmo_ipa_msgb_cb_proto_ext(msg)); diff --git a/examples/stream-client.c b/examples/stream-client.c index cae0153..6d20263 100644 --- a/examples/stream-client.c +++ b/examples/stream-client.c @@ -54,10 +54,17 @@ static int disconnect_cb(struct osmo_stream_cli *conn) return 0; } -static int read_cb(struct osmo_stream_cli *conn, struct msgb *msg) +static int read_cb(struct osmo_stream_cli *conn, int res, struct msgb *msg) { LOGP(DSTREAMTEST, LOGL_NOTICE, "receiving message from stream... "); + if (res < 0) { + LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message (res = %d)\n", res); + msgb_free(msg); + return 0; + } + + LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d bytes: %s\n", msg->len, msgb_hexdump(msg)); msgb_free(msg); diff --git a/examples/stream-server.c b/examples/stream-server.c index f6332dc..5295c2b 100644 --- a/examples/stream-server.c +++ b/examples/stream-server.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <errno.h> #include <osmocom/core/select.h> #include <osmocom/core/socket.h> @@ -44,10 +45,20 @@ void sighandler(int foo) signal(SIGINT, SIG_DFL); } -int read_cb(struct osmo_stream_srv *conn, struct msgb *msg) +int read_cb(struct osmo_stream_srv *conn, int res, struct msgb *msg) { LOGP(DSTREAMTEST, LOGL_NOTICE, "receiving message from stream... "); + if (res <= 0) { + if (res < 0) + LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message: %s\n", strerror(-res)); + else + LOGPC(DSTREAMTEST, LOGL_ERROR, "client closed connection\n"); + msgb_free(msg); + osmo_stream_srv_destroy(conn); + return -EBADF; + } + LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d bytes: %s\n", msg->len, msgb_hexdump(msg)); msgb_free(msg); |