Commit Graph

44 Commits

Author SHA1 Message Date
Harald Welte 0b08d518f2 socket, select: Fix -Wsign-compare warnings
Change-Id: Idf6213e66e9bf609e930c6134292458a7d521871
2022-01-10 10:53:03 +01:00
Oliver Smith d841bec8d2 select_main: don't poll forever during shutdown
Do not poll without timeout during shutdown if no timers are pending.

Change-Id: I81c64a7ae440304522c2179c212023a566ddced8
2021-12-28 12:14:12 +00:00
Philipp Maier b1ef8f5f69 select: gather statistics for TCP connections
osmocom applications are deployed in a variety of different situations.
Dependung on the medium that interconnects the network components
unexpected behaviour may occur. To debug problems with the
interconnection between network components it might help to monitor the
health of the related TCP connections.

Change-Id: I1416f95aff2adcf13689646b7574845de169fa3d
Related: SYS#5701
2021-12-23 14:52:15 +00:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Neels Hofmeyr ac49bda4d4 osmo_select_shutdown_request(): allow finishing pending writes on SIGTERM
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
2021-06-18 12:22:44 +00:00
Harald Welte b904e428aa select: Migrate over to poll()
select is an ancient interface with weird restrictions, such as
the fact that it cannot be used for file descriptor values > 1024.

This may have been sufficient 40 years ago, but certainly is not in
2020.  I wanted to migrate to epoll(), but unfortunately it doesn't
work well with the fact that existing programs simply set osmo_fd.flags
without making any API calls at the time they change those flags.

So let's do the migration to poll() as a first step, and then consider
epoll() as a second step further down the road, after introducing new
APIs and porting applications over.

The poll() code introduced in this patch is not extremely efficient,
as it needs to do extensive linked list iterations after poll() returns
in order to find the osmo_fd from the fd.  Optimization is possible,
but let's postpone that to a follow-up patch.

At compile time, a new --enable-force-io-select argument can be given
to configure, forcing the use of the old select() backend instead of the
new poll() based backend.

Change-Id: I9e80da68a144b36926066610d0d3df06abe09bca
2020-10-23 15:09:05 +00:00
Harald Welte 7e65791b66 select: Introduce osmo_fd_{read,write}_{enable,disable}()
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-10-19 09:54:17 +00:00
Pau Espin d05def0885 Drop old BSC references in fd check configure option
Change-Id: I053c2bfe461aa82085e7dac1cdcc95dd77219949
2020-05-11 17:24:16 +00:00
Alexander Chemeris e8ec214a77 select: Fix typo in a comment Osmcoom->Osmocom
Change-Id: I6fb4d20d149abc724d477420b5eba482a0b63259
2020-05-09 00:37:09 +00:00
Harald Welte 100e44ed49 timerfd: call osmo_fd_unregister() when closing on read error
Change-Id: I8513126286083ebf02d14043cf072c8297878dd7
2020-04-19 08:27:27 +00:00
Harald Welte a70ac85f5b select.c: Introduce support for signalfd
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
2020-04-18 21:16:12 +02:00
Harald Welte 7a010b10f7 select: Make file descriptor lists per-thread
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-11-07 10:24:50 +01:00
Harald Welte 2d90611cb0 context: Add support for [per-thread] global talloc contexts
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-08-27 13:43:31 +02:00
Harald Welte 1688699c3f select: Rename BSC_FD_* constants to OSMO_FD_*
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
2019-03-21 16:02:01 +00:00
Harald Welte 52a8375025 select: Call log_reset_context() before calling file descriptor callbacks
Make sure to clear any log context before processing the next incoming message
as part of some file descriptor callback.  This effectively prevents "context
leaking" from processing of one message into processing of the next message as part
of one iteration through the list of file descriptors here.

Change-Id: I3644c7bc1a9cec5858eb0faf94efc8c3ba7f5d8d
Closes: OS#3813
2019-02-21 16:38:49 +01:00
Harald Welte 37608f911d timerfd_create(): Fix error handling of osmo_fd_register()
Change-Id: Ia2528cc3e3155bbc9cb32dee0e3af99cc6e1c654
Closes: Coverity CID#188853
2018-10-21 13:46:07 +02:00
Harald Welte ea4d8939af Add osmo_timerfd_* functions for osmo_fd-wrapped timerfd
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
2018-05-10 10:33:54 +02:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Harald Welte 6c0a0e645d add osmo_fd_setup() convenience function to fill-in osmo_fd
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-08-12 11:43:14 +02:00
Harald Welte ea91a51ebe select: Add new osmo_fd_close() function
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-07-13 16:03:37 +02:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
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-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
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-06-23 00:18:22 +00:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Harald Welte 1d604d8be4 src/select.c: Don't #include <sys/select.h> if it doesn't exist
We have to #include <sys/select.h> inside the block protected by
HAVE_SYS_SELECT_H, otherwise it will fail on (embedded) builds where
that file doesn't exist, such as the arm-none-eabi target on Debian
stable and Ubuntu 16.04.

Change-Id: I82a2dcbc55b6ee0e914881c5e09b80506c5de4f2
2017-05-17 15:32:35 +01:00
Holger Hans Peter Freyther ff20641d9e select: Find the highest fd when filling the fd_sets
Instead of returning maxfd, which is the highest fd ever seen, take
the highest we have seen on this iteration.

This makes a tiny difference for the osmo-sip-connector and its
event loop integration. select.c ignores the return value of this
function right now.

This was seen while debugging the eventloop integration of the
osmo-sip-connector before and after a VTY connection. The fds
being polled didn't go down.

Change-Id: I1a6d7271273ec08bb511c21b936891bc508843e4
2017-04-04 20:14:32 +00:00
Philipp Maier b288853ffa select: add functionality to check socket state
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
2017-02-07 13:39:00 +01:00
Neels Hofmeyr 9c0751fc60 osmo_select_main(): drop useless call to osmo_timers_check()
osmo_timers_check() does nothing more than counting the active timers. It is of
no use to count them when not using the return value in any way.

Change-Id: I8d35ca90a4c16d6f1c7f9793d663e5479783efed
2016-09-28 10:48:46 +00:00
Harald Welte 2d2e2cca0d Update doxygen annotations in libosmocore
This adds and improves doxygen API descriptions all over libosmocore,
reducing the 'white spots' that don't have any documentation.
2016-05-05 18:49:27 +02:00
Holger Hans Peter Freyther 61f28880d5 select: Externalize fd_set filling and dispatch
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-31 16:56:51 +02:00
Harald Welte 6c33ae2605 Add new osmo_fd_get_by_fd() function
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.
2016-03-19 21:17:58 +01:00
Jaroslav Škarvada 2b82c1c6c8 fix FSF address in sources/headers
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
2015-11-12 13:46:05 +01:00
Harald Welte 9e166e8e08 select.c: Add missing #include lines for string.h and sys/select.h
This is needed on Nuttx.
2014-11-14 15:21:01 +01:00
Holger Hans Peter Freyther 92e1e70dba select: Fix english in comment 2014-05-15 21:40:15 +02:00
Sylvain Munaut dca7d2caaa doc: Fix the Doxygen section endings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18 21:53:23 +02:00
Harald Welte ba6988bd89 some more doxygen work (include the notion of modules) 2011-08-17 17:14:11 +02:00
Harald Welte 32e1f239b3 merge process.[ch] with application.[ch] 2011-06-26 14:14:05 +02:00
Pablo Neira Ayuso f7f89d0cfe select: use namespace prefix osmo_fd* and osmo_select*
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-05-07 13:00:51 +02:00
Pablo Neira Ayuso 0b21c1c885 timer: use namespace prefix osmo_timer*
Summary of changes:

s/struct timer_list/struct osmo_timer_list/g
s/bsc_add_timer/osmo_timer_add/g
s/bsc_schedule_timer/osmo_timer_schedule/g
s/bsc_del_timer/osmo_timer_del/g
s/bsc_timer_pending/osmo_timer_pending/g
s/bsc_nearest_timer/osmo_timers_nearest/g
s/bsc_prepare_timers/osmo_timers_prepare/g
s/bsc_update_timers/osmo_timers_update/g
s/bsc_timer_check/osmo_timers_check/g
2011-05-07 13:00:51 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
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>
2011-03-23 18:09:28 +01:00
Harald Welte 9d92f0e12c select.c: Change license terms from GPLv2 (from ulogd) to GPLv2+ 2010-10-31 13:56:45 +01:00
Holger Hans Peter Freyther 43558316bc bsc_fd: Add a build option to be able to debug fd list corruption
bsc_register_fd on an already registered fd can corrupt the list
in a heavy way and make the select end in an infinite loop, this
code will workaround the issue and provide a way to set a breakpoint
at the right position in the code.
2010-08-06 06:50:23 +08:00
Holger Hans Peter Freyther 23ba4747d1 select.c: Make the ugly hacker uglier...
Right now I'm seeing crashes when removing a link and deleting
it and I need this hack to make it not crash. We will have to
understand if llist_for_each_entry_safe has a bug or if we are
doing something bad with the list (anchors not properly initialized).
2010-04-11 17:34:52 +02:00
Harald Welte 5484480211 fix select.c build (config.h) 2010-02-20 22:23:08 +01:00
Harald Welte ec8b4501c7 intial checkin of the libosmocore project 2010-02-20 20:34:29 +01:00