mirror of https://gerrit.osmocom.org/libosmocore
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
This commit is contained in:
parent
e988ec3b53
commit
4ec4a38f92
|
@ -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 */
|
/* All other failure and success cases are handled here */
|
||||||
switch (msghdr->action) {
|
switch (msghdr->action) {
|
||||||
case IOFD_ACT_WRITE:
|
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;
|
break;
|
||||||
case IOFD_ACT_SENDTO:
|
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;
|
break;
|
||||||
case IOFD_ACT_SENDMSG:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
OSMO_ASSERT(0);
|
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);
|
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);
|
struct iofd_msghdr *msghdr = iofd_msghdr_alloc(iofd, IOFD_ACT_WRITE, msg, 0);
|
||||||
if (!msghdr)
|
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);
|
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);
|
struct iofd_msghdr *msghdr = iofd_msghdr_alloc(iofd, IOFD_ACT_SENDTO, msg, 0);
|
||||||
if (!msghdr)
|
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);
|
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))) {
|
if (OSMO_UNLIKELY(msgh->msg_namelen > sizeof(msghdr->osa))) {
|
||||||
LOGPIO(iofd, LOGL_ERROR, "osmo_iofd_sendmsg msg_namelen (%u) > supported %zu bytes\n",
|
LOGPIO(iofd, LOGL_ERROR, "osmo_iofd_sendmsg msg_namelen (%u) > supported %zu bytes\n",
|
||||||
|
|
Loading…
Reference in New Issue