arehbein has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/33346 )
Change subject: core/osmo_io: Fix reception of partial packets
......................................................................
core/osmo_io: Fix reception of partial packets
Add/use field 'pending_incomplete' to 'struct osmo_io_fd', so that osmo_io
logic
knows when the next incoming octets don't mark the start of a new message.
Change-Id: I0ab8028c807b4181fddd3c00ea2e037c40cf0813
---
M src/core/osmo_io.c
M src/core/osmo_io_internal.h
M src/core/osmo_io_poll.c
3 files changed, 19 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/46/33346/1
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index b0287ec..39e03d6 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -273,6 +273,7 @@
{
int res;
struct msgb *pending = NULL;
+ bool pending_incomplete;
if (rc <= 0) {
iofd->io_ops.read_cb(iofd, rc, msg);
@@ -281,7 +282,8 @@
do {
res = iofd_handle_segmentation(iofd, msg, &pending);
- if (res != IOFD_SEG_ACT_DEFER || rc < 0)
+ pending_incomplete = (res == IOFD_SEG_ACT_DEFER);
+ if (!pending_incomplete || rc < 0)
iofd->io_ops.read_cb(iofd, rc, msg);
if (res == IOFD_SEG_ACT_HANDLE_MORE)
msg = pending;
@@ -289,6 +291,7 @@
OSMO_ASSERT(iofd->pending == NULL);
iofd->pending = pending;
+ iofd->pending_incomplete = pending_incomplete;
}
/* Public functions */
diff --git a/src/core/osmo_io_internal.h b/src/core/osmo_io_internal.h
index bdd2ac5..b66832b 100644
--- a/src/core/osmo_io_internal.h
+++ b/src/core/osmo_io_internal.h
@@ -50,6 +50,8 @@
struct osmo_io_ops io_ops;
/*! Pending msgb to keep partial data during segmentation */
struct msgb *pending;
+ /*! 'true' if and only if field 'pending' consists of an incomplete
packet */
+ bool pending_incomplete;
/*! data pointer passed through to call-back function */
void *data;
diff --git a/src/core/osmo_io_poll.c b/src/core/osmo_io_poll.c
index dd86f29..795390a 100644
--- a/src/core/osmo_io_poll.c
+++ b/src/core/osmo_io_poll.c
@@ -56,7 +56,7 @@
}
hdr.msg = msg;
- hdr.iov[0].iov_base = msgb_data(msg);
+ hdr.iov[0].iov_base = iofd->pending_incomplete ? msg->tail : msgb_data(msg);
hdr.iov[0].iov_len = msgb_tailroom(msg);
hdr.hdr.msg_iov = &hdr.iov[0];
hdr.hdr.msg_iovlen = 1;
--
To view, visit
https://gerrit.osmocom.org/c/libosmocore/+/33346
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0ab8028c807b4181fddd3c00ea2e037c40cf0813
Gerrit-Change-Number: 33346
Gerrit-PatchSet: 1
Gerrit-Owner: arehbein <arehbein(a)sysmocom.de>
Gerrit-MessageType: newchange