pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-netif/+/34074 )

Change subject: stream: Append data to current tail of message upon recv()
......................................................................

stream: Append data to current tail of message upon recv()

The previous behavior was not standarized, and even erratic under some
code paths (passing msgb_data() and size=msgb_tailroom()).
This patch standarizes the behavior, and makes it possible to append
content if the user wishes so instead of erasing old data in the msgb
passed to it.

Change-Id: I2cfcd4f61545e6a76d84495c3467999efccf22df
---
M src/stream_cli.c
M src/stream_srv.c
2 files changed, 21 insertions(+), 5 deletions(-)

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




diff --git a/src/stream_cli.c b/src/stream_cli.c
index 9845f14..0e075b8 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -917,7 +917,7 @@
        OSMO_ASSERT(cli);
        OSMO_ASSERT(msg);

-       ret = recv(cli->ofd.fd, msg->data, msg->data_len, 0);
+       ret = recv(cli->ofd.fd, msg->tail, msgb_tailroom(msg), 0);
        if (ret < 0) {
                if (errno == EPIPE || errno == ECONNRESET)
                        LOGSCLI(cli, LOGL_ERROR, "lost connection with srv\n");
diff --git a/src/stream_srv.c b/src/stream_srv.c
index 4d8d4d3..be43a80 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -826,14 +826,15 @@
        struct sctp_sndrcvinfo sinfo;
        int flags = 0;
        int ret;
+       uint8_t *data = msg->tail;

-       ret = sctp_recvmsg(fd, msgb_data(msg), msgb_tailroom(msg),
+       ret = sctp_recvmsg(fd, data, msgb_tailroom(msg),
                        NULL, NULL, &sinfo, &flags);
        msgb_sctp_msg_flags(msg) = 0;
        msgb_sctp_ppid(msg) = ntohl(sinfo.sinfo_ppid);
        msgb_sctp_stream(msg) = sinfo.sinfo_stream;
        if (flags & MSG_NOTIFICATION) {
-               union sctp_notification *notif = (union sctp_notification 
*)msgb_data(msg);
+               union sctp_notification *notif = (union sctp_notification 
*)data;
                LOGP(DLINP, LOGL_DEBUG, "NOTIFICATION %u flags=0x%x\n", 
notif->sn_header.sn_type, notif->sn_header.sn_flags);
                msgb_put(msg, sizeof(union sctp_notification));
                msgb_sctp_msg_flags(msg) = 
OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION;
@@ -908,7 +909,7 @@

        switch (conn->srv->sk_domain) {
        case AF_UNIX:
-               ret = recv(conn->ofd.fd, msgb_data(msg), msgb_tailroom(msg), 0);
+               ret = recv(conn->ofd.fd, msg->tail, msgb_tailroom(msg), 0);
                break;
        case AF_INET:
        case AF_INET6:
@@ -921,7 +922,7 @@
 #endif
                case IPPROTO_TCP:
                default:
-                       ret = recv(conn->ofd.fd, msgb_data(msg), 
msgb_tailroom(msg), 0);
+                       ret = recv(conn->ofd.fd, msg->tail, msgb_tailroom(msg), 
0);
                        break;
                }
                break;

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

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I2cfcd4f61545e6a76d84495c3467999efccf22df
Gerrit-Change-Number: 34074
Gerrit-PatchSet: 3
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to