libosmocore  0.10.2
Osmocom core library
Select loop abstraction

select() loop abstraction More...

Files

file  select.h
 select loop abstraction.
 
file  select.c
 select filedescriptor handling.
 

Data Structures

struct  osmo_fd
 Structure representing a file dsecriptor. More...
 

Macros

#define BSC_FD_READ   0x0001
 Indicate interest in reading from the file descriptor. More...
 
#define BSC_FD_WRITE   0x0002
 Indicate interest in writing to the file descriptor. More...
 
#define BSC_FD_EXCEPT   0x0004
 Indicate interest in exceptions from the file descriptor. More...
 

Functions

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. More...
 
bool osmo_fd_is_registered (struct osmo_fd *fd)
 Check if a file descriptor is already registered. More...
 
int osmo_fd_register (struct osmo_fd *fd)
 Register a new file descriptor with select loop abstraction. More...
 
void osmo_fd_unregister (struct osmo_fd *fd)
 Unregister a file descriptor from select loop abstraction. More...
 
void osmo_fd_close (struct osmo_fd *fd)
 Close a file descriptor, mark it as closed + unregister from select loop abstraction. More...
 
int osmo_select_main (int polling)
 select main loop integration More...
 
struct osmo_fdosmo_fd_get_by_fd (int fd)
 find an osmo_fd based on the integer fd More...
 
int osmo_fd_fill_fds (void *_rset, void *_wset, void *_eset)
 Populate the fd_sets and return the highest fd number. More...
 
int osmo_fd_disp_fds (void *readset, void *writeset, void *exceptset)
 
static LLIST_HEAD (osmo_fds)
 

Variables

static int maxfd = 0
 
static int unregistered_count
 

Detailed Description

select() loop abstraction

Macro Definition Documentation

◆ BSC_FD_EXCEPT

#define BSC_FD_EXCEPT   0x0004

Indicate interest in exceptions from the file descriptor.

Referenced by osmo_fd_disp_fds(), osmo_fd_fill_fds(), and osmo_wqueue_bfd_cb().

◆ BSC_FD_READ

#define BSC_FD_READ   0x0001

Indicate interest in reading from the file descriptor.

Referenced by gsmtap_sink_fd_cb(), gsmtap_source_add_sink(), osmo_fd_disp_fds(), osmo_fd_fill_fds(), osmo_fd_init_ofd(), and osmo_wqueue_bfd_cb().

◆ BSC_FD_WRITE

#define BSC_FD_WRITE   0x0002

Indicate interest in writing to the file descriptor.

Referenced by osmo_fd_disp_fds(), osmo_fd_fill_fds(), osmo_wqueue_bfd_cb(), osmo_wqueue_clear(), and osmo_wqueue_enqueue().

Function Documentation

◆ LLIST_HEAD()

static LLIST_HEAD ( osmo_fds  )
static

◆ osmo_fd_close()

void osmo_fd_close ( struct osmo_fd fd)

Close a file descriptor, mark it as closed + unregister from select loop abstraction.

Parameters
[in]fdosmocom file descriptor to be unregistered + closed

If fd is registered, we unregister it from the select() loop abstraction. We then close the fd and set it to -1, as well as unsetting any 'when' flags

References osmo_fd::fd, osmo_fd_is_registered(), osmo_fd_unregister(), and osmo_fd::when.

◆ osmo_fd_disp_fds()

int osmo_fd_disp_fds ( void *  readset,
void *  writeset,
void *  exceptset 
)
inline

◆ osmo_fd_fill_fds()

int osmo_fd_fill_fds ( void *  _rset,
void *  _wset,
void *  _eset 
)
inline

Populate the fd_sets and return the highest fd number.

Parameters
[in]_rsetThe readfds to populate
[in]_wsetThe wrtiefds to populate
[in]_esetThe errorfds to populate
Returns
The highest file descriptor seen or 0 on an empty list

References BSC_FD_EXCEPT, BSC_FD_READ, BSC_FD_WRITE, osmo_fd::fd, osmo_fd::list, llist_for_each_entry, and osmo_fd::when.

Referenced by osmo_select_main().

◆ osmo_fd_get_by_fd()

struct osmo_fd * osmo_fd_get_by_fd ( int  fd)

find an osmo_fd based on the integer fd

Parameters
[in]fdfile descriptor to use as search key
Returns
osmo_fd for fd; NULL in case it doesn't exist

References osmo_fd::fd, osmo_fd::list, and llist_for_each_entry.

◆ osmo_fd_is_registered()

bool osmo_fd_is_registered ( struct osmo_fd fd)

Check if a file descriptor is already registered.

Parameters
[in]fdosmocom file descriptor to be checked
Returns
true if registered; otherwise false

References osmo_fd::list, and llist_for_each_entry.

Referenced by osmo_fd_close(), and osmo_fd_register().

◆ osmo_fd_register()

int osmo_fd_register ( struct osmo_fd fd)

Register a new file descriptor with select loop abstraction.

Parameters
[in]fdosmocom file descriptor to be registered
Returns
0 on success; negative in case of error

References osmo_fd::fd, osmo_fd::list, llist_add_tail(), maxfd, and osmo_fd_is_registered().

Referenced by gsmtap_source_add_sink(), gsmtap_source_init(), and osmo_fd_init_ofd().

◆ osmo_fd_setup()

void osmo_fd_setup ( struct osmo_fd ofd,
int  fd,
unsigned int  when,
int(*)(struct osmo_fd *fd, unsigned int what)  cb,
void *  data,
unsigned int  priv_nr 
)

Set up an osmo-fd.

Will not register it.

Parameters
[in,out]ofdOsmo FD to be set-up
[in]fdOS-level file descriptor number
[in]whenbit-mask of BSC_FD_{READ,WRITE,EXECEPT}
[in]cbCall-back function to be called
[in]dataPrivate context pointer
[in]priv_nrPrivate number

References osmo_fd::cb, osmo_fd::data, osmo_fd::fd, osmo_fd::priv_nr, and osmo_fd::when.

◆ osmo_fd_unregister()

void osmo_fd_unregister ( struct osmo_fd fd)

Unregister a file descriptor from select loop abstraction.

Parameters
[in]fdosmocom file descriptor to be unregistered

References osmo_fd::list, llist_del(), and unregistered_count.

Referenced by osmo_fd_close().

◆ osmo_select_main()

int osmo_select_main ( int  polling)

select main loop integration

Parameters
[in]pollingshould we pollonly (1) or block on select (0)
Returns
0 if no fd handled; 1 if fd handled; negative in case of error

References maxfd, osmo_fd_disp_fds(), osmo_fd_fill_fds(), osmo_timers_nearest(), osmo_timers_prepare(), and osmo_timers_update().

Variable Documentation

◆ maxfd

int maxfd = 0
static

◆ unregistered_count

int unregistered_count
static