diff options
-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 |