From 4ec4a38f92dd49739cd0a8f61e8f253343b0e979 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 16 Mar 2024 19:04:15 +0100 Subject: [PATCH] osmo_io: Make {write,sendto,sendmsg} completion callback optional There are situations (like multicast datagram transmit) where we don't really care about the result of a write operation, and hence don't need a write completion callback. As the completed message buffer is free'd by core osmo_io, there is no leak in doing so. Change-Id: I0c071a29e508884bac331ada5e510bbfcf440bbf --- src/core/osmo_io.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c index 83b67b58f..b589cb71c 100644 --- a/src/core/osmo_io.c +++ b/src/core/osmo_io.c @@ -397,13 +397,16 @@ void iofd_handle_send_completion(struct osmo_io_fd *iofd, int rc, struct iofd_ms /* All other failure and success cases are handled here */ switch (msghdr->action) { case IOFD_ACT_WRITE: - iofd->io_ops.write_cb(iofd, rc, msg); + if (iofd->io_ops.write_cb) + iofd->io_ops.write_cb(iofd, rc, msg); break; case IOFD_ACT_SENDTO: - iofd->io_ops.sendto_cb(iofd, rc, msg, &msghdr->osa); + if (iofd->io_ops.sendto_cb) + iofd->io_ops.sendto_cb(iofd, rc, msg, &msghdr->osa); break; case IOFD_ACT_SENDMSG: - iofd->io_ops.sendmsg_cb(iofd, rc, msg); + if (iofd->io_ops.sendmsg_cb) + iofd->io_ops.sendmsg_cb(iofd, rc, msg); break; default: OSMO_ASSERT(0); @@ -439,10 +442,6 @@ int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg) } OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_READ_WRITE); - if (OSMO_UNLIKELY(!iofd->io_ops.write_cb)) { - LOGPIO(iofd, LOGL_ERROR, "write_cb not set, Rejecting msgb\n"); - return -EINVAL; - } struct iofd_msghdr *msghdr = iofd_msghdr_alloc(iofd, IOFD_ACT_WRITE, msg, 0); if (!msghdr) @@ -490,10 +489,6 @@ int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, int sendto_ } OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_RECVFROM_SENDTO); - if (OSMO_UNLIKELY(!iofd->io_ops.sendto_cb)) { - LOGPIO(iofd, LOGL_ERROR, "sendto_cb not set, Rejecting msgb\n"); - return -EINVAL; - } struct iofd_msghdr *msghdr = iofd_msghdr_alloc(iofd, IOFD_ACT_SENDTO, msg, 0); if (!msghdr) @@ -547,10 +542,6 @@ int osmo_iofd_sendmsg_msgb(struct osmo_io_fd *iofd, struct msgb *msg, int sendms } OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_RECVMSG_SENDMSG); - if (OSMO_UNLIKELY(!iofd->io_ops.sendmsg_cb)) { - LOGPIO(iofd, LOGL_ERROR, "sendmsg_cb not set, Rejecting msgb\n"); - return -EINVAL; - } if (OSMO_UNLIKELY(msgh->msg_namelen > sizeof(msghdr->osa))) { LOGPIO(iofd, LOGL_ERROR, "osmo_iofd_sendmsg msg_namelen (%u) > supported %zu bytes\n",