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>
|
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 */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define BSC_FD_READ 0x0001
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Indicate interest in writing to the file descriptor */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define BSC_FD_WRITE 0x0002
|
2017-06-19 22:17:59 +00:00
|
|
|
/*! Indicate interest in exceptions from the file descriptor */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define BSC_FD_EXCEPT 0x0004
|
|
|
|
|
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;
|
2011-08-16 21:26:52 +00:00
|
|
|
/*! bit-mask or of \ref BSC_FD_READ, \ref BSC_FD_WRITE and/or
|
|
|
|
* \ref BSC_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;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
int osmo_select_main(int polling);
|
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);
|
|
|
|
|
2012-04-18 19:53:23 +00:00
|
|
|
/*! @} */
|