diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-08-04 14:33:32 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2023-08-07 19:16:24 +0200 |
commit | a69a958ae38c289f068d91b073015c90ee5ff514 (patch) | |
tree | a124e4bca47813054874c6e1c877a878270e392d | |
parent | b8fb69542b9913ade7e2e115872659d0f8dad191 (diff) |
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
-rw-r--r-- | src/stream_cli.c | 2 | ||||
-rw-r--r-- | src/stream_srv.c | 9 |
2 files changed, 6 insertions, 5 deletions
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 @@ int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg) 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 @@ static int _sctp_recvmsg_wrapper(int fd, struct msgb *msg) 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 @@ int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg) 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 @@ int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg) #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; |