Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file select.h |
| 2 | * select loop abstraction. |
| 3 | */ |
| 4 | |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 5 | #pragma once |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 6 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 7 | #include <osmocom/core/linuxlist.h> |
Philipp Maier | b288853 | 2016-12-09 14:07:18 +0100 | [diff] [blame] | 8 | #include <stdbool.h> |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 9 | |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 10 | /*! \defgroup select Select loop abstraction |
| 11 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 12 | * \file select.h */ |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 13 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 14 | /*! Indicate interest in reading from the file descriptor */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 15 | #define BSC_FD_READ 0x0001 |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 16 | /*! Indicate interest in writing to the file descriptor */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 17 | #define BSC_FD_WRITE 0x0002 |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 18 | /*! Indicate interest in exceptions from the file descriptor */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 19 | #define BSC_FD_EXCEPT 0x0004 |
| 20 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 21 | /*! Structure representing a file dsecriptor */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 22 | struct osmo_fd { |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 23 | /*! linked list for internal management */ |
| 24 | struct llist_head list; |
| 25 | /*! actual operating-system level file decriptor */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 26 | int fd; |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 27 | /*! bit-mask or of \ref BSC_FD_READ, \ref BSC_FD_WRITE and/or |
| 28 | * \ref BSC_FD_EXCEPT */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 29 | unsigned int when; |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 30 | /*! call-back function to be called once file descriptor becomes |
| 31 | * available */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 32 | int (*cb)(struct osmo_fd *fd, unsigned int what); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 33 | /*! data pointer passed through to call-back function */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 34 | void *data; |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 35 | /*! private number, extending \a data */ |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 36 | unsigned int priv_nr; |
| 37 | }; |
| 38 | |
Philipp Maier | b288853 | 2016-12-09 14:07:18 +0100 | [diff] [blame] | 39 | bool osmo_fd_is_registered(struct osmo_fd *fd); |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 40 | int osmo_fd_register(struct osmo_fd *fd); |
| 41 | void osmo_fd_unregister(struct osmo_fd *fd); |
| 42 | int osmo_select_main(int polling); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame] | 43 | |
Harald Welte | 6c33ae2 | 2016-03-19 21:17:58 +0100 | [diff] [blame] | 44 | struct osmo_fd *osmo_fd_get_by_fd(int fd); |
| 45 | |
Holger Hans Peter Freyther | 61f2888 | 2016-03-21 09:55:05 +0100 | [diff] [blame] | 46 | /* |
| 47 | * foreign event loop integration |
| 48 | */ |
| 49 | int osmo_fd_fill_fds(void *readset, void *writeset, void *exceptset); |
| 50 | int osmo_fd_disp_fds(void *readset, void *writeset, void *exceptset); |
| 51 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 52 | /*! @} */ |