daniel has uploaded this change for review.

View Change

osmo_io: Improve handling of segmentation_cb

The read length is not needed int the segmentation callback, msgb
already has all the necessary information, the parameter previously was
just msgb_length(msg).

Also handle negative return values (except -EAGAIN) of the callback as
errors which cause the msg to be dropped. -EAGAIN will defer the msg.

Change-Id: I6a0eebb8d4490f09a3cc6eb97d4ff47b4a8fd377
---
M include/osmocom/core/osmo_io.h
M src/core/osmo_io.c
2 files changed, 29 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/58/32758/1
diff --git a/include/osmocom/core/osmo_io.h b/include/osmocom/core/osmo_io.h
index ffc8cfa..db9805b 100644
--- a/include/osmocom/core/osmo_io.h
+++ b/include/osmocom/core/osmo_io.h
@@ -43,7 +43,7 @@
void (*write_cb)(struct osmo_io_fd *iofd, int res,
const struct msgb *msg);
/*! call-back function to segment the data returned by read_cb */
- int (*segmentation_cb)(struct msgb *msg, int data_len);
+ int (*segmentation_cb)(struct msgb *msg);
};

/* mode OSMO_IO_FD_MODE_RECVFROM_SENDTO: */
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index cfb6d68..b52b838 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -229,7 +229,18 @@
return IOFD_SEG_ACT_HANDLE_ONE;
}

- int len = iofd->io_ops.segmentation_cb(msg, msg_len);
+ int len = iofd->io_ops.segmentation_cb(msg);
+ if (len == -EAGAIN) {
+ LOGPIO(iofd, LOGL_DEBUG, "segmentation_cb returned EAGAIN\n");
+ *pending_out = msg;
+ return IOFD_SEG_ACT_DEFER;
+ } else if (len < 0) {
+ /* Something is wrong, skip this msgb */
+ LOGPIO(iofd, LOGL_ERROR, "segmentation_cb returned error (%i), skipping msg of size %i\n", len, msg_len);
+ *pending_out = NULL;
+ msgb_free(msg);
+ return IOFD_SEG_ACT_DEFER;
+ }

pending_len = msg_len - len;
/* No segmentation needed, return */

To view, visit change 32758. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I6a0eebb8d4490f09a3cc6eb97d4ff47b4a8fd377
Gerrit-Change-Number: 32758
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann@sysmocom.de>
Gerrit-MessageType: newchange