2017-06-20 02:35:06 +00:00
|
|
|
/*! \file select.h
|
|
|
|
* select loop abstraction.
|
|
|
|
*/
|
|
|
|
|
2014-06-16 08:13:40 +00:00
|
|
|
#pragma once
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-03-22 15:36:13 +00:00
|
|
|
#include <osmocom/core/linuxlist.h>
|
2016-12-09 13:07:18 +00:00
|
|
|
#include <stdbool.h>
|
2017-12-03 15:13:39 +00:00
|
|
|
#include <time.h>
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-08-17 10:46:48 +00:00
|
|
|
/*! \defgroup select Select loop abstraction
|
|
|
|
* @{
|
2017-06-20 02:35:06 +00:00
|
|
|
* \file select.h */
|
2011-08-16 21:26:52 +00:00
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Indicate interest in reading from the file descriptor */
|
2019-03-20 09:26:39 +00:00
|
|
|
#define OSMO_FD_READ 0x0001
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Indicate interest in writing to the file descriptor */
|
2019-03-20 09:26:39 +00:00
|
|
|
#define OSMO_FD_WRITE 0x0002
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Indicate interest in exceptions from the file descriptor */
|
2019-03-20 09:26:39 +00:00
|
|
|
#define OSMO_FD_EXCEPT 0x0004
|
|
|
|
|
|
|
|
/* legacy naming dating back to early OpenBSC / bsc_hack of 2008 */
|
|
|
|
#define BSC_FD_READ OSMO_FD_READ
|
|
|
|
#define BSC_FD_WRITE OSMO_FD_WRITE
|
|
|
|
#define BSC_FD_EXCEPT OSMO_FD_EXCEPT
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Structure representing a file dsecriptor */
|
2011-05-07 10:42:40 +00:00
|
|
|
struct osmo_fd {
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! linked list for internal management */
|
|
|
|
struct llist_head list;
|
|
|
|
/*! actual operating-system level file decriptor */
|
2010-02-20 19:34:29 +00:00
|
|
|
int fd;
|
2019-03-20 09:26:39 +00:00
|
|
|
/*! bit-mask or of \ref OSMO_FD_READ, \ref OSMO_FD_WRITE and/or
|
|
|
|
* \ref OSMO_FD_EXCEPT */
|
2010-02-20 19:34:29 +00:00
|
|
|
unsigned int when;
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! call-back function to be called once file descriptor becomes
|
|
|
|
* available */
|
2011-05-07 10:42:40 +00:00
|
|
|
int (*cb)(struct osmo_fd *fd, unsigned int what);
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! data pointer passed through to call-back function */
|
2010-02-20 19:34:29 +00:00
|
|
|
void *data;
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! private number, extending \a data */
|
2010-02-20 19:34:29 +00:00
|
|
|
unsigned int priv_nr;
|
|
|
|
};
|
|
|
|
|
2017-08-12 09:43:14 +00:00
|
|
|
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);
|
|
|
|
|
2016-12-09 13:07:18 +00:00
|
|
|
bool osmo_fd_is_registered(struct osmo_fd *fd);
|
2011-05-07 10:42:40 +00:00
|
|
|
int osmo_fd_register(struct osmo_fd *fd);
|
|
|
|
void osmo_fd_unregister(struct osmo_fd *fd);
|
2017-07-13 12:28:30 +00:00
|
|
|
void osmo_fd_close(struct osmo_fd *fd);
|
2011-05-07 10:42:40 +00:00
|
|
|
int osmo_select_main(int polling);
|
2019-03-18 16:17:43 +00:00
|
|
|
int osmo_select_main_ctx(int polling);
|
2019-04-06 11:46:40 +00:00
|
|
|
void osmo_select_init(void);
|
2011-08-16 21:26:52 +00:00
|
|
|
|
2016-03-19 20:17:58 +00:00
|
|
|
struct osmo_fd *osmo_fd_get_by_fd(int fd);
|
|
|
|
|
2016-03-21 08:55:05 +00:00
|
|
|
/*
|
|
|
|
* foreign event loop integration
|
|
|
|
*/
|
|
|
|
int osmo_fd_fill_fds(void *readset, void *writeset, void *exceptset);
|
|
|
|
int osmo_fd_disp_fds(void *readset, void *writeset, void *exceptset);
|
|
|
|
|
2017-12-03 15:13:39 +00:00
|
|
|
/* timerfd integration */
|
|
|
|
int osmo_timerfd_disable(struct osmo_fd *ofd);
|
|
|
|
int osmo_timerfd_schedule(struct osmo_fd *ofd, const struct timespec *first,
|
|
|
|
const struct timespec *interval);
|
|
|
|
int osmo_timerfd_setup(struct osmo_fd *ofd, int (*cb)(struct osmo_fd *, unsigned int), void *data);
|
|
|
|
|
2012-04-18 19:53:23 +00:00
|
|
|
/*! @} */
|