diff options
author | Max <msuraev@sysmocom.de> | 2019-01-29 18:11:13 +0100 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2019-01-29 18:20:34 +0100 |
commit | f8767012c83a762cca7f05ebc0729c227bc303c9 (patch) | |
tree | 3a861afb4fdd952790c09a5b454428c27bb0f4f2 /examples | |
parent | 5c7bf3b23da5971a26483a0396fc85fc2c714739 (diff) |
Stream examples: log sent/received bytes
Make client and server examples more verbose by logging actual bytes
sent/received.
Change-Id: I6979b2f92c96c2366f18bf31e4bc495a6709133a
Diffstat (limited to 'examples')
-rw-r--r-- | examples/stream-client.c | 17 | ||||
-rw-r--r-- | examples/stream-server.c | 16 |
2 files changed, 23 insertions, 10 deletions
diff --git a/examples/stream-client.c b/examples/stream-client.c index 3c3416f..6178dcd 100644 --- a/examples/stream-client.c +++ b/examples/stream-client.c @@ -45,19 +45,26 @@ static int connect_cb(struct osmo_stream_cli *conn) static int read_cb(struct osmo_stream_cli *conn) { + int bytes; struct msgb *msg; - LOGP(DSTREAMTEST, LOGL_NOTICE, "received message from stream\n"); + LOGP(DSTREAMTEST, LOGL_NOTICE, "receiving message from stream... "); msg = msgb_alloc(1024, "STREAMCLIENT/test"); if (msg == NULL) { - LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n"); + LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n"); return 0; } - if (osmo_stream_cli_recv(conn, msg) < 0) { - LOGP(DSTREAMTEST, LOGL_ERROR, "cannot receive message\n"); + + 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)); + msgb_free(msg); return 0; } @@ -86,7 +93,7 @@ static int kbd_cb(struct osmo_fd *fd, unsigned int what) osmo_stream_cli_send(conn, msg); - LOGP(DSTREAMTEST, LOGL_NOTICE, "message of %d bytes sent\n", msg->len); + LOGP(DSTREAMTEST, LOGL_NOTICE, "sent %d bytes message: %s\n", msg->len, msgb_hexdump(msg)); return 0; } diff --git a/examples/stream-server.c b/examples/stream-server.c index 08c3d2a..cd6dc57 100644 --- a/examples/stream-server.c +++ b/examples/stream-server.c @@ -43,19 +43,25 @@ void sighandler(int foo) int read_cb(struct osmo_stream_srv *conn) { + int bytes; struct msgb *msg; - LOGP(DSTREAMTEST, LOGL_NOTICE, "received message from stream\n"); + LOGP(DSTREAMTEST, LOGL_NOTICE, "receiving message from stream... "); msg = msgb_alloc(1024, "STREAMSERVER/test"); if (msg == NULL) { - LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n"); + LOGPC(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"); + + bytes = osmo_stream_srv_recv(conn, msg); + + if (bytes < 0) { + LOGPC(DSTREAMTEST, LOGL_ERROR, "cannot receive message: %s\n", strerror(-bytes)); return 0; - } + } else + LOGPC(DSTREAMTEST, LOGL_NOTICE, "got %d (%d) bytes: %s\n", bytes, msg->len, msgb_hexdump(msg)); + msgb_free(msg); return 0; } |