aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/select.h
AgeCommit message (Collapse)AuthorFilesLines
2022-11-03Support building with -Werror=strict-prototypes / -Werror=old-style-definitionHarald Welte1-3/+3
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that uses constructs of earlier C standards, which were abandoned in C99. See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for some related discussion. Change-Id: I84fd99442d0cc400fa562fa33623c142649230e2
2021-06-18osmo_select_shutdown_request(): allow finishing pending writes on SIGTERMNeels Hofmeyr1-0/+3
Allow telling osmo_select_main* to only service pending writes (shutdown mode). Introduce API fuctions to indicate a shutdown request, and find out whether shutdown is complete. Some osmo programs have a curious sleep of few seconds upon receiving SIGTERM. The idea presumably was to finish off pending writes before halting the program. But a sleep() on program exit is annoying, especially when there usually are no pending writes, and when osmo-bsc is launched numerous times for tests. Change-Id: Ib94d4316924103459577087c2214188679db2227
2020-10-19select: Introduce osmo_fd_{read,write}_{enable,disable}()Harald Welte1-0/+20
If we watn to migrate to something like epoll(), user application code must call a function of the libosmocore API whenever it changes its read/write interest in a file descriptor. Let's introduce API so applications can be ported to this API, before making direct 'ofd->when' manipulations illegal as a second step. Change-Id: Idb89ba7bc7c129a6304a76900d17f47daf54d17d
2020-04-18select.c: Introduce support for signalfdHarald Welte1-0/+18
The signalfd(2) mechanism of Linux allows signals to be delivered and processed via normal file descriptor I/O. This avoids any of the usual problems about re-entrancy of signal processing, as signals can be processed from the osmocom select() loop abstraction just like any other event. Change-Id: If8d89dd1f6989e1cd9b9367fad954d65f91ada30
2019-11-07select: Make file descriptor lists per-threadHarald Welte1-0/+1
In a multi-threaded environemnt, it's likely that each thread will have its own, distinct set of file descriptors that it wants to watch. Hence, let's make the osmo_fd_* functions configure not one global list of file descriptors, but a thread-local list of file descriptors. Change-Id: I5082ed3e500ad1a7516e1785bc57e008da2fac9a
2019-08-27context: Add support for [per-thread] global talloc contextsHarald Welte1-0/+1
Rather than having applications maintain their own talloc cotexts, let's offer some root talloc contexts in libosmocore. Let's also make them per thread right from the beginning. This will help some multi-threaded applications to use talloc in a thread-safe way. Change-Id: Iae39cd57274bf6753ecaf186f229e582b42662e3
2019-03-21select: Rename BSC_FD_* constants to OSMO_FD_*Harald Welte1-5/+10
The naming of these constants dates back to when the code was private within OpenBSC. Everything else was renamed (bsc_fd -> osmo_fd) at the time, but somehow the BSC_FD_* defines have been missed at the time. Keep compatibility #defines around, but allow us to migrate the applications to a less confusing naming meanwhile. Change-Id: Ifae33ed61a7cf0ae54ad487399e7dd2489986436
2018-05-10Add osmo_timerfd_* functions for osmo_fd-wrapped timerfdHarald Welte1-0/+7
Linux offers file descriptor based periodic (interval) timers, which can achieve a higher precision than our userspace based timers and which can be slave'd to CLOCK_MONOTINIC or other clock sources. Let's add some code for osmo_fd wrapped versions that integrate well with our select() abstraction. The code has been used in osmo-bts-trx since June 2017 (change-id I51b19adde14ebb7ef3bb863d45e06243c323e22e), and I'm just renaming and moving it to libosmocore here. After a merge, the osmo-bts implementations can be removed in favor if this one. Change-Id: Ibeffba7c997252c003723bcd5d14122c4ded2fe7
2017-08-12add osmo_fd_setup() convenience function to fill-in osmo_fdHarald Welte1-0/+4
This basically follows the concept of osmo_timer_setup() and allows the caller to fill-in all configurable fields of osmo_fd in one line of code, rather than open-coding it in 5 lines everywhere. Change-Id: I6dbf19ea22fd65302bfc5424c10418d1b7939094
2017-07-13select: Add new osmo_fd_close() functionHarald Welte1-0/+1
This is a convenience helper that will both close a fd, mark it as closed and unregister it from the event loop abstraction. In most cases, you probably actually want to use it instead of manually closing and calling osmo_fd_unregister(). Change-Id: Icd0933eed6a24edde7cdcb378e138897ecc5332c
2017-06-23doxygen: unify use of \file across the boardNeels Hofmeyr1-5/+5
Considering the various styles and implications found in the sources, edit scores of files to follow the same API doc guidelines around the doxygen grouping and the \file tag. Many files now show a short description in the generated API doc that was so far only available as C comment. The guidelines and reasoning behind it is documented at https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation In some instances, remove file comments and add to the corresponding group instead, to be shared among several files (e.g. bitvec). Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr1-5/+5
Especially for short descriptions, it is annoying to have to type \brief for every single API doc. Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes the first sentence of an API doc as the brief description. Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-02-07select: add functionality to check socket statePhilipp Maier1-0/+2
osmo_fd_register() is used to register socket file descriptors, after registering a socket, there is no way to test if the socket is still registered or actually registered at all. This commit adds a new function osmo_fd_register_check() that can be used to check in advance, if the socket fd is registered, before performing further operations. Change-Id: I48ec7098d6bba586c81bf0d5c9088108e2c081c6
2016-03-31select: Externalize fd_set filling and dispatchHolger Hans Peter Freyther1-0/+6
To integrate with an external event loop (in this case glib) we need to allow an application to get a filled out fd_set and then dispatch it. osmo_fds and maxfds are static and I decided to keep it that way and instead create two routines to fill the fdset and then one to dispatch the result. The public header file does not include sys/select.h and we can compile the library without select, so I didn't want to require having to include this file, and used void * for the parameter. Mark the routines as inline to avoid a call from the select function. I have confirmed that inlining has an effect on x86 using Debian's gcc-4.9.2-10 compiler
2016-03-19Add new osmo_fd_get_by_fd() functionHarald Welte1-0/+2
This function can be used to obtain the osmo_fd corresponding to a given fd. The latter can be useful when integrating libosmocore main loop with other libraries.
2014-06-16include: Switch to #pragma once patternSylvain Munaut1-4/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18doc: Fix the Doxygen section endingsSylvain Munaut1-1/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-08-17some more doxygen work (include the notion of modules)Harald Welte1-11/+6
2011-08-16start to add doxygen documentation to libosmocore headersHarald Welte1-1/+29
2011-05-07select: use namespace prefix osmo_fd* and osmo_select*Pablo Neira Ayuso1-5/+5
Summary of changes: s/struct bsc_fd/struct osmo_fd/g s/bsc_register_fd/osmo_fd_register/g s/bsc_unregister_fd/osmo_fd_unregister/g s/bsc_select_main/osmo_select_main/g
2011-03-23include: reorganize headers file to include/osmocom/[gsm|core]0.2.0Pablo Neira Ayuso1-0/+22
This patch moves all GSM-specific definitions to include/osmocom/gsm. Moreover, the headers in include/osmocore/ have been moved to include/osmocom/core. This has been proposed by Harald Welte and Sylvain Munaunt. Tested with `make distcheck'. Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>