pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/41300?usp=email )
Change subject: io_uring: Avoid extra reads if iofd becomes unregistered by user ......................................................................
io_uring: Avoid extra reads if iofd becomes unregistered by user
The user callback (read_cb, segmentation_cb, etc.) may decide to unregister the iofd instead of closing it. In this scenario, we should avoid calling the callback further until the iofd is registered again.
Change-Id: I231d5a16768b730f67089090c244bcc10dc69c3a --- M src/core/osmo_io_uring.c M tests/osmo_io/osmo_io_test.c 2 files changed, 3 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/00/41300/1
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c index 01b8063..e4a87ad 100644 --- a/src/core/osmo_io_uring.c +++ b/src/core/osmo_io_uring.c @@ -359,7 +359,7 @@ }
/* Check for every iteration, because iofd might get unregistered/closed during receive function. */ - if (iofd->u.uring.read.enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED)) + if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED) && iofd->u.uring.read.enabled) iofd_handle_recv(iofd, msg, chunk, msghdr); else msgb_free(msg); @@ -372,7 +372,7 @@ msghdr->msg[idx] = NULL; }
- if (iofd->u.uring.read.enabled && !IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED)) + if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED) && iofd->u.uring.read.enabled) iofd_uring_submit_recv(iofd, msghdr->action);
iofd_msghdr_free(msghdr); diff --git a/tests/osmo_io/osmo_io_test.c b/tests/osmo_io/osmo_io_test.c index 0812ea8..06491a7 100644 --- a/tests/osmo_io/osmo_io_test.c +++ b/tests/osmo_io/osmo_io_test.c @@ -280,7 +280,7 @@ } else { OSMO_ASSERT(rc == 0); file_eof_read = true; - osmo_iofd_close(iofd); + osmo_iofd_unregister(iofd); } talloc_free(msg); }