pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-netif/+/42191?usp=email )

Change subject: stream: Improve error handling and logging in write_cb
......................................................................

stream: Improve error handling and logging in write_cb

Nowhere in man 2 write/send/sendmsg it can be read that a return of 0
is actually an error, so avoid handling that case as error in
stream_cli.

While at ti, log the errno string.

Change-Id: I68468f0452cbc86b6210bbd1dbfa251579270adb
---
M src/stream_cli.c
M src/stream_srv.c
2 files changed, 9 insertions(+), 4 deletions(-)

Approvals:
  pespin: Looks good to me, approved
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  osmith: Looks good to me, but someone else must approve




diff --git a/src/stream_cli.c b/src/stream_cli.c
index e59122b..a8b5fa6 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -604,8 +604,10 @@
                (void)stream_cli_handle_connecting(cli, res);
                break;
        case STREAM_CLI_STATE_CONNECTED:
-               if (msg && res <= 0) {
-                       LOGSCLI(cli, LOGL_ERROR, "received error %d in response 
to send\n", res);
+               if (msg && res < 0) {
+                       char errbuf[64];
+                       strerror_r(-res, errbuf, sizeof(errbuf));
+                       LOGSCLI(cli, LOGL_ERROR, "error to send: %d (%s)\n", 
res, errbuf);
                        (void)stream_cli_reconnect(cli);
                }
                /* res=0 && msgb=NULL: "connected notify", but we already 
received before a read_cb
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 140515f..6c4eada 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -801,8 +801,11 @@
        struct osmo_stream_srv *conn = osmo_iofd_get_data(iofd);
        LOGSSRV(conn, LOGL_DEBUG, "connected write\n");

-       if (res < 0)
-               LOGSSRV(conn, LOGL_ERROR, "error to send: %s\n", 
strerror(errno));
+       if (res < 0) {
+               char errbuf[64];
+               strerror_r(-res, errbuf, sizeof(errbuf));
+               LOGSSRV(conn, LOGL_ERROR, "error to send: %d (%s)\n", res, 
errbuf);
+       }

        if (osmo_iofd_txqueue_len(iofd) == 0)
                if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY)

--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/42191?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I68468f0452cbc86b6210bbd1dbfa251579270adb
Gerrit-Change-Number: 42191
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to