select.h
Go to the documentation of this file.
#pragma once
#include <osmocom/core/linuxlist.h>
#include <stdbool.h>
#include <time.h>
#define BSC_FD_READ 0x0001
#define BSC_FD_WRITE 0x0002
#define BSC_FD_EXCEPT 0x0004
struct osmo_fd {
struct llist_head list;
int fd;
unsigned int when;
int (*cb)(struct osmo_fd *fd, unsigned int what);
void *data;
unsigned int priv_nr;
};
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);
bool osmo_fd_is_registered(struct osmo_fd *fd);
int osmo_fd_register(struct osmo_fd *fd);
void osmo_fd_unregister(struct osmo_fd *fd);
void osmo_fd_close(struct osmo_fd *fd);
int osmo_select_main(int polling);
struct osmo_fd *osmo_fd_get_by_fd(int fd);
/*
* 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);
/* 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);
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