mirror of https://gerrit.osmocom.org/libosmocore
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
This commit is contained in:
parent
2c59d1285e
commit
63e45e6c6a
|
@ -88,5 +88,6 @@ void osmo_iofd_set_priv_nr(struct osmo_io_fd *iofd, unsigned int priv_nr);
|
|||
|
||||
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);
|
||||
|
|
|
@ -258,6 +258,7 @@ osmo_iofd_free;
|
|||
osmo_iofd_get_data;
|
||||
osmo_iofd_get_fd;
|
||||
osmo_iofd_get_name;
|
||||
osmo_iofd_set_name;
|
||||
osmo_iofd_get_priv_nr;
|
||||
osmo_iofd_init;
|
||||
osmo_iofd_ops;
|
||||
|
|
|
@ -128,7 +128,8 @@ struct msgb *iofd_msgb_alloc(struct osmo_io_fd *iofd)
|
|||
|
||||
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*/
|
||||
|
@ -388,7 +389,8 @@ struct osmo_io_fd *osmo_iofd_setup(const void *ctx, int fd, const char *name, en
|
|||
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;
|
||||
|
@ -578,6 +580,14 @@ const char *osmo_iofd_get_name(const struct osmo_io_fd *iofd)
|
|||
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 */
|
||||
|
|
|
@ -44,7 +44,7 @@ struct osmo_io_fd {
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue