pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/39067?usp=email )
Change subject: osmo_io: Use early return to simplify code ......................................................................
osmo_io: Use early return to simplify code
Change-Id: Idd4c4f2da7f15b86ddd4765c60680130af08b22d --- M src/core/osmo_io_uring.c 1 file changed, 19 insertions(+), 17 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/67/39067/1
diff --git a/src/core/osmo_io_uring.c b/src/core/osmo_io_uring.c index 569f150..1b1f997 100644 --- a/src/core/osmo_io_uring.c +++ b/src/core/osmo_io_uring.c @@ -498,24 +498,26 @@
static void iofd_uring_notify_connected(struct osmo_io_fd *iofd) { - if (iofd->mode == OSMO_IO_FD_MODE_RECVMSG_SENDMSG) { - /* Don't call this function after enabling read or write. */ - OSMO_ASSERT(!iofd->u.uring.write_enabled && !iofd->u.uring.read_enabled); - - /* Use a temporary osmo_fd which we can use to notify us once the connection is established - * or failed (indicated by FD becoming writable). - * This is needed as (at least for SCTP sockets) one cannot submit a zero-length writev/sendmsg - * in order to get notification when the socekt is writable.*/ - if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED)) { - osmo_fd_setup(&iofd->u.uring.connect_ofd, iofd->fd, OSMO_FD_WRITE, - iofd_uring_connected_cb, iofd, 0); - if (osmo_fd_register(&iofd->u.uring.connect_ofd) < 0) - LOGPIO(iofd, LOGL_ERROR, "Failed to register FD for connect event.\n"); - else - IOFD_FLAG_SET(iofd, IOFD_FLAG_NOTIFY_CONNECTED); - } - } else + if (iofd->mode != OSMO_IO_FD_MODE_RECVMSG_SENDMSG) { iofd_uring_write_enable(iofd); + return; + } + + /* OSMO_IO_FD_MODE_RECVMSG_SENDMSG: Don't call this function after enabling read or write. */ + OSMO_ASSERT(!iofd->u.uring.write_enabled && !iofd->u.uring.read_enabled); + + /* Use a temporary osmo_fd which we can use to notify us once the connection is established + * or failed (indicated by FD becoming writable). + * This is needed as (at least for SCTP sockets) one cannot submit a zero-length writev/sendmsg + * in order to get notification when the socekt is writable.*/ + if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_NOTIFY_CONNECTED)) { + osmo_fd_setup(&iofd->u.uring.connect_ofd, iofd->fd, OSMO_FD_WRITE, + iofd_uring_connected_cb, iofd, 0); + if (osmo_fd_register(&iofd->u.uring.connect_ofd) < 0) + LOGPIO(iofd, LOGL_ERROR, "Failed to register FD for connect event.\n"); + else + IOFD_FLAG_SET(iofd, IOFD_FLAG_NOTIFY_CONNECTED); + } }
const struct iofd_backend_ops iofd_uring_ops = {