arehbein has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/34750?usp=email )


Change subject: osmo_io: Add possibility to resend a message
......................................................................

osmo_io: Add possibility to resend a message

Add osmo_iofd_rewrite_msgb(), which works like osmo_iofd_write_msgb(), except
it doesn't check the message queue length and it enqueues at the front
of the message queue.

Change-Id: I9cc588294fcaee49e334282183672aa32fa30bee
---
M TODO-RELEASE
M include/osmocom/core/osmo_io.h
M src/core/libosmocore.map
M src/core/osmo_io.c
4 files changed, 48 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/50/34750/1

diff --git a/TODO-RELEASE b/TODO-RELEASE
index b67161d..2945c2b 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -9,3 +9,4 @@
 #library       what                    description / commit summary line
 core      ADD       osmo_sock_multiaddr_{add,del}_local_addr()
 core      ADD       gsmtap_inst_fd2() core, DEPRECATE gsmtap_inst_fd()
+core      ADD       osmo_iofd_rewrite_msgb()
diff --git a/include/osmocom/core/osmo_io.h b/include/osmocom/core/osmo_io.h
index b3d248f..23335ff 100644
--- a/include/osmocom/core/osmo_io.h
+++ b/include/osmocom/core/osmo_io.h
@@ -83,6 +83,7 @@
 void osmo_iofd_notify_connected(struct osmo_io_fd *iofd);

 int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg);
+int osmo_iofd_rewrite_msgb(struct osmo_io_fd *iofd, struct msgb *msg);
 int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, int 
sendto_flags,
                          const struct osmo_sockaddr *dest);

diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index e5f8bd8..6d04d34 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -278,6 +278,7 @@
 osmo_iofd_uring_init;
 osmo_iofd_notify_connected;
 osmo_iofd_write_msgb;
+osmo_iofd_rewrite_msgb;
 osmo_ip_str_type;
 osmo_isdnhdlc_decode;
 osmo_isdnhdlc_encode;
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index 2b2b7dd..894a0c1 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -381,6 +381,38 @@
        return 0;
 }

+/*! Resend a message through a connected socket.
+ *
+ *  Appends the message to the front of the internal transmit queue. This 
function
+ *  will always enqueue the message, even if the maximum number of messages is 
reached.
+ *  This can be used to emulate Osmocom write queue API behavior (with write 
queues,
+ *  if the call to the write callback returns -EAGAIN, the message buffer that 
failed
+ *  to be sent is enqueued at the front of the write queue by the write queue 
backend).
+ *  \param[in] iofd file descriptor to write to
+ *  \param[in] msg message buffer to write
+ */
+int osmo_iofd_rewrite_msgb(struct osmo_io_fd *iofd, struct msgb *msg)
+{
+       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);
+       if (!msghdr)
+               return -ENOMEM;
+
+       msghdr->flags = MSG_NOSIGNAL;
+       msghdr->iov[0].iov_base = msgb_data(msghdr->msg);
+       msghdr->iov[0].iov_len = msgb_length(msghdr->msg);
+       msghdr->hdr.msg_iov = &msghdr->iov[0];
+       msghdr->hdr.msg_iovlen = 1;
+
+       iofd_txqueue_enqueue_front(iofd, msghdr);
+
+       return 0;
+}
+
 /*! Send a message through an unconnected socket.
  *
  *  Appends the message to the internal transmit queue.

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/34750?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I9cc588294fcaee49e334282183672aa32fa30bee
Gerrit-Change-Number: 34750
Gerrit-PatchSet: 1
Gerrit-Owner: arehbein <arehb...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to