blob: 9b5f372bf6bd37a98876a6e689ed7c9c16ef27fe [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file select.h
2 * select loop abstraction.
3 */
4
Sylvain Munaut12ba7782014-06-16 10:13:40 +02005#pragma once
Harald Welteec8b4502010-02-20 20:34:29 +01006
Pablo Neira Ayuso83419342011-03-22 16:36:13 +01007#include <osmocom/core/linuxlist.h>
Philipp Maierb2888532016-12-09 14:07:18 +01008#include <stdbool.h>
Harald Welteec8b4502010-02-20 20:34:29 +01009
Harald Welteba6988b2011-08-17 12:46:48 +020010/*! \defgroup select Select loop abstraction
11 * @{
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020012 * \file select.h */
Harald Weltebd598e32011-08-16 23:26:52 +020013
Neels Hofmeyr87e45502017-06-20 00:17:59 +020014/*! Indicate interest in reading from the file descriptor */
Harald Welteec8b4502010-02-20 20:34:29 +010015#define BSC_FD_READ 0x0001
Neels Hofmeyr87e45502017-06-20 00:17:59 +020016/*! Indicate interest in writing to the file descriptor */
Harald Welteec8b4502010-02-20 20:34:29 +010017#define BSC_FD_WRITE 0x0002
Neels Hofmeyr87e45502017-06-20 00:17:59 +020018/*! Indicate interest in exceptions from the file descriptor */
Harald Welteec8b4502010-02-20 20:34:29 +010019#define BSC_FD_EXCEPT 0x0004
20
Neels Hofmeyr87e45502017-06-20 00:17:59 +020021/*! Structure representing a file dsecriptor */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020022struct osmo_fd {
Harald Weltebd598e32011-08-16 23:26:52 +020023 /*! linked list for internal management */
24 struct llist_head list;
25 /*! actual operating-system level file decriptor */
Harald Welteec8b4502010-02-20 20:34:29 +010026 int fd;
Harald Weltebd598e32011-08-16 23:26:52 +020027 /*! bit-mask or of \ref BSC_FD_READ, \ref BSC_FD_WRITE and/or
28 * \ref BSC_FD_EXCEPT */
Harald Welteec8b4502010-02-20 20:34:29 +010029 unsigned int when;
Harald Weltebd598e32011-08-16 23:26:52 +020030 /*! call-back function to be called once file descriptor becomes
31 * available */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020032 int (*cb)(struct osmo_fd *fd, unsigned int what);
Harald Weltebd598e32011-08-16 23:26:52 +020033 /*! data pointer passed through to call-back function */
Harald Welteec8b4502010-02-20 20:34:29 +010034 void *data;
Harald Weltebd598e32011-08-16 23:26:52 +020035 /*! private number, extending \a data */
Harald Welteec8b4502010-02-20 20:34:29 +010036 unsigned int priv_nr;
37};
38
Philipp Maierb2888532016-12-09 14:07:18 +010039bool osmo_fd_is_registered(struct osmo_fd *fd);
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020040int osmo_fd_register(struct osmo_fd *fd);
41void osmo_fd_unregister(struct osmo_fd *fd);
42int osmo_select_main(int polling);
Harald Weltebd598e32011-08-16 23:26:52 +020043
Harald Welte6c33ae22016-03-19 21:17:58 +010044struct osmo_fd *osmo_fd_get_by_fd(int fd);
45
Holger Hans Peter Freyther61f28882016-03-21 09:55:05 +010046/*
47 * foreign event loop integration
48 */
49int osmo_fd_fill_fds(void *readset, void *writeset, void *exceptset);
50int osmo_fd_disp_fds(void *readset, void *writeset, void *exceptset);
51
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020052/*! @} */