aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-09-27 16:46:25 +0200
committerlaforge <laforge@osmocom.org>2020-09-29 16:58:11 +0000
commitc433889bba6f3886411b8b0ef9d7318c4c8444b3 (patch)
tree0c789140975b4870eea52549f51f777808479c97
parentf44937834f177bfec96fd84b07751e30553feb27 (diff)
write_queue: Re-enqueue msgb if write_cb returns -EAGAIN
By adding this functionality, the write_cb() handler can "un-dequeue" the msgb in case of some error. The msgb might have been modified meanwhile, e.g. due to a partial write already pulling some data off the head of the msgb. Change-Id: I97bb0d64ec991adf5dd0b3708e0c7cf029e03b5f
-rw-r--r--src/write_queue.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/write_queue.c b/src/write_queue.c
index 422eda44..b208b25e 100644
--- a/src/write_queue.c
+++ b/src/write_queue.c
@@ -68,10 +68,15 @@ int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what)
/* the queue might have been emptied */
if (msg) {
rc = queue->write_cb(fd, msg);
- msgb_free(msg);
-
- if (rc == -EBADF)
+ if (rc == -EBADF) {
+ msgb_free(msg);
goto err_badfd;
+ } else if (rc == -EAGAIN) {
+ /* re-enqueue the msgb to the head of the queue */
+ llist_add(&msg->list, &queue->msg_queue);
+ queue->current_length++;
+ } else
+ msgb_free(msg);
if (!llist_empty(&queue->msg_queue))
fd->when |= OSMO_FD_WRITE;