libosmocore  0.12.0
Osmocom core library
select.h
Go to the documentation of this file.
1 
5 #pragma once
6 
8 #include <stdbool.h>
9 #include <time.h>
10 
16 #define BSC_FD_READ 0x0001
17 
18 #define BSC_FD_WRITE 0x0002
19 
20 #define BSC_FD_EXCEPT 0x0004
21 
23 struct osmo_fd {
25  struct llist_head list;
27  int fd;
30  unsigned int when;
33  int (*cb)(struct osmo_fd *fd, unsigned int what);
35  void *data;
37  unsigned int priv_nr;
38 };
39 
40 void osmo_fd_setup(struct osmo_fd *ofd, int fd, unsigned int when,
41  int (*cb)(struct osmo_fd *fd, unsigned int what),
42  void *data, unsigned int priv_nr);
43 
44 bool osmo_fd_is_registered(struct osmo_fd *fd);
45 int osmo_fd_register(struct osmo_fd *fd);
46 void osmo_fd_unregister(struct osmo_fd *fd);
47 void osmo_fd_close(struct osmo_fd *fd);
48 int osmo_select_main(int polling);
49 
50 struct osmo_fd *osmo_fd_get_by_fd(int fd);
51 
52 /*
53  * foreign event loop integration
54  */
55 int osmo_fd_fill_fds(void *readset, void *writeset, void *exceptset);
56 int osmo_fd_disp_fds(void *readset, void *writeset, void *exceptset);
57 
58 /* timerfd integration */
59 int osmo_timerfd_disable(struct osmo_fd *ofd);
60 int osmo_timerfd_schedule(struct osmo_fd *ofd, const struct timespec *first,
61  const struct timespec *interval);
62 int osmo_timerfd_setup(struct osmo_fd *ofd, int (*cb)(struct osmo_fd *, unsigned int), void *data);
63 
osmo_fd_disp_fds
int osmo_fd_disp_fds(void *readset, void *writeset, void *exceptset)
Definition: select.c:189
osmo_fd::priv_nr
unsigned int priv_nr
private number, extending data
Definition: select.h:37
osmo_fd_register
int osmo_fd_register(struct osmo_fd *fd)
Register a new file descriptor with select loop abstraction.
Definition: select.c:93
osmo_fd::cb
int(* cb)(struct osmo_fd *fd, unsigned int what)
call-back function to be called once file descriptor becomes available
Definition: select.h:33
osmo_fd_setup
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)
Set up an osmo-fd.
Definition: select.c:62
osmo_fd_unregister
void osmo_fd_unregister(struct osmo_fd *fd)
Unregister a file descriptor from select loop abstraction.
Definition: select.c:134
osmo_fd_is_registered
bool osmo_fd_is_registered(struct osmo_fd *fd)
Check if a file descriptor is already registered.
Definition: select.c:77
osmo_fd::list
struct llist_head list
linked list for internal management
Definition: select.h:25
osmo_fd_close
void osmo_fd_close(struct osmo_fd *fd)
Close a file descriptor, mark it as closed + unregister from select loop abstraction.
Definition: select.c:149
osmo_fd::when
unsigned int when
bit-mask or of BSC_FD_READ, BSC_FD_WRITE and/or BSC_FD_EXCEPT
Definition: select.h:30
osmo_timerfd_disable
int osmo_timerfd_disable(struct osmo_fd *ofd)
disable the osmocom-wrapped timerfd
Definition: select.c:278
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
osmo_timerfd_setup
int osmo_timerfd_setup(struct osmo_fd *ofd, int(*cb)(struct osmo_fd *, unsigned int), void *data)
setup osmocom-wrapped timerfd
Definition: select.c:320
osmo_fd_fill_fds
int osmo_fd_fill_fds(void *readset, void *writeset, void *exceptset)
Populate the fd_sets and return the highest fd number.
Definition: select.c:166
osmo_timerfd_schedule
int osmo_timerfd_schedule(struct osmo_fd *ofd, const struct timespec *first, const struct timespec *interval)
schedule the osmcoom-wrapped timerfd to occur first at first, then periodically at interval
Definition: select.c:292
osmo_fd
Structure representing a file dsecriptor.
Definition: select.h:23
osmo_fd_get_by_fd
struct osmo_fd * osmo_fd_get_by_fd(int fd)
find an osmo_fd based on the integer fd
Definition: select.c:263
linuxlist.h
osmo_fd::fd
int fd
actual operating-system level file decriptor
Definition: select.h:27
osmo_fd::data
void * data
data pointer passed through to call-back function
Definition: select.h:35
osmo_select_main
int osmo_select_main(int polling)
select main loop integration
Definition: select.c:234