diff options
author | Harald Welte <laforge@osmocom.org> | 2020-10-18 22:07:21 +0200 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2020-10-19 09:54:17 +0000 |
commit | 7e65791b665477a654b2c905e9b31b5832a814fc (patch) | |
tree | de16fc3ecc767eb9a71866c42a2eaaf69056f2e0 | |
parent | fa2d66ca1808e8bcd9bcf95737f08b071032187f (diff) |
select: Introduce osmo_fd_{read,write}_{enable,disable}()
If we watn to migrate to something like epoll(), user application
code must call a function of the libosmocore API whenever it changes
its read/write interest in a file descriptor.
Let's introduce API so applications can be ported to this API,
before making direct 'ofd->when' manipulations illegal as a second step.
Change-Id: Idb89ba7bc7c129a6304a76900d17f47daf54d17d
-rw-r--r-- | include/osmocom/core/select.h | 20 | ||||
-rw-r--r-- | src/select.c | 9 |
2 files changed, 29 insertions, 0 deletions
diff --git a/include/osmocom/core/select.h b/include/osmocom/core/select.h index bc601982..b4101998 100644 --- a/include/osmocom/core/select.h +++ b/include/osmocom/core/select.h @@ -19,6 +19,8 @@ #define OSMO_FD_WRITE 0x0002 /*! Indicate interest in exceptions from the file descriptor */ #define OSMO_FD_EXCEPT 0x0004 +/*! Used as when_mask in osmo_fd_update_when() */ +#define OSMO_FD_MASK 0xFFFF /* legacy naming dating back to early OpenBSC / bsc_hack of 2008 */ #define BSC_FD_READ OSMO_FD_READ @@ -47,6 +49,24 @@ void osmo_fd_setup(struct osmo_fd *ofd, int fd, unsigned int when, int (*cb)(struct osmo_fd *fd, unsigned int what), void *data, unsigned int priv_nr); +void osmo_fd_update_when(struct osmo_fd *ofd, unsigned int when_mask, unsigned int when); + +static inline void osmo_fd_read_enable(struct osmo_fd *ofd) { + osmo_fd_update_when(ofd, OSMO_FD_MASK, OSMO_FD_READ); +} + +static inline void osmo_fd_read_disable(struct osmo_fd *ofd) { + osmo_fd_update_when(ofd, ~OSMO_FD_READ, 0); +} + +static inline void osmo_fd_write_enable(struct osmo_fd *ofd) { + osmo_fd_update_when(ofd, OSMO_FD_MASK, OSMO_FD_WRITE); +} + +static inline void osmo_fd_write_disable(struct osmo_fd *ofd) { + osmo_fd_update_when(ofd, ~OSMO_FD_WRITE, 0); +} + bool osmo_fd_is_registered(struct osmo_fd *fd); int osmo_fd_register(struct osmo_fd *fd); void osmo_fd_unregister(struct osmo_fd *fd); diff --git a/src/select.c b/src/select.c index 496beea9..1bb354b9 100644 --- a/src/select.c +++ b/src/select.c @@ -75,6 +75,15 @@ void osmo_fd_setup(struct osmo_fd *ofd, int fd, unsigned int when, ofd->priv_nr = priv_nr; } +/*! Update the 'when' field of osmo_fd. "ofd->when = (ofd->when & when_mask) | when". + * Use this function instead of directly modifying ofd->when, as the latter will be + * removed soon. */ +void osmo_fd_update_when(struct osmo_fd *ofd, unsigned int when_mask, unsigned int when) +{ + ofd->when &= when_mask; + ofd->when |= when; +} + /*! Check if a file descriptor is already registered * \param[in] fd osmocom file descriptor to be checked * \returns true if registered; otherwise false |