pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/33341 )


Change subject: osmo_io: Make name optional, add _set_name() API
......................................................................

osmo_io: Make name optional, add _set_name() API

This allows renaming the iofd at any later point in time. This is useful
for instance if the parent object holding the iofd changes its name.

Change-Id: If2772a3ccaa98616e0189862a49ab0243435e343
---
M include/osmocom/core/osmo_io.h
M src/core/osmo_io.c
M src/core/osmo_io_internal.h
3 files changed, 26 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/41/33341/1

diff --git a/include/osmocom/core/osmo_io.h b/include/osmocom/core/osmo_io.h
index d278ce0..aac25a3 100644
--- a/include/osmocom/core/osmo_io.h
+++ b/include/osmocom/core/osmo_io.h
@@ -88,5 +88,6 @@

 int osmo_iofd_get_fd(const struct osmo_io_fd *iofd);
 const char *osmo_iofd_get_name(const struct osmo_io_fd *iofd);
+void osmo_iofd_set_name(struct osmo_io_fd *iofd, const char *name);

 void osmo_iofd_set_ioops(struct osmo_io_fd *iofd, const struct osmo_io_ops 
*ioops);
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index d260da4..d72a52d 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -128,7 +128,8 @@

        OSMO_ASSERT(iofd->msgb_alloc.size < 0xffff - headroom);
        return msgb_alloc_headroom_c(iofd->msgb_alloc.ctx,
-                                    iofd->msgb_alloc.size + headroom, 
headroom, iofd->name);
+                                    iofd->msgb_alloc.size + headroom, headroom,
+                                    iofd->name ? : "iofd_msgb");
 }

 /*! return the pending msgb in iofd or NULL if there is none*/
@@ -387,7 +388,8 @@
        iofd->fd = fd;
        iofd->mode = mode;

-       iofd->name = talloc_strdup(iofd, name);
+       if (name)
+               iofd->name = talloc_strdup(iofd, name);

        if (ioops)
                iofd->io_ops = *ioops;
@@ -577,6 +579,14 @@
        return iofd->name;
 }

+/*! Set the name of the file descriptor
+ *  \param[in] iofd the file descriptor
+ *  \param[in] name the name to set on the file descriptor */
+void osmo_iofd_set_name(struct osmo_io_fd *iofd, const char *name)
+{
+       osmo_talloc_replace_string(iofd, &iofd->name, name);
+}
+
 /*! Set the osmo_io_ops for an iofd
  *  \param[in] iofd Target iofd file descriptor
  *  \param[in] ioops osmo_io_ops structure to be set */
diff --git a/src/core/osmo_io_internal.h b/src/core/osmo_io_internal.h
index bdd2ac5..cd620e7 100644
--- a/src/core/osmo_io_internal.h
+++ b/src/core/osmo_io_internal.h
@@ -44,7 +44,7 @@
        bool to_free;

        /*! human-readable name to associte with fd */
-       const char *name;
+       char *name;

        /*! send/recv (msg) callback functions */
        struct osmo_io_ops io_ops;

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33341
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If2772a3ccaa98616e0189862a49ab0243435e343
Gerrit-Change-Number: 33341
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to