mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 06:33:31 +00:00
bf92232698
This patch is the first step of re-organizing the internal structure of the libc. The original version involved many direct calls of global functions (often with side effects) across compilation units, which made the control flow (e.g., the initialization sequence) hard to follow. The new version replaces those ad-hoc interactions with dedicated interfaces (like suspend.h, resume.h, select.h, current_time.h). The underlying facilities are provided by the central Libc::Kernel and selectively propagated to the various compilation units. The latter is done by a sequence of 'init_*' calls, which eventually will be replaced by constructor calls. The addition of new headers increases the chance for name clashes with existing (public) headers. To disambiguate libc-internal header files from public headers, this patch moves the former into a new 'internal/' subdirectory. This makes the include directives easier to follow and the libc's source-tree structure more tidy. There are still a few legacies left, which cannot easily be removed right now (e.g., because noux relies on them). However, the patch moves those bad apples to legacy.h and legacy.cc, which highlights the deprecation of those functions. Issue #3497
71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
/*
|
|
* \brief Support for handling select() in LibC components
|
|
* \author Christian Helmuth
|
|
* \date 2017-02-13
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2017 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__LIBC__SELECT_H_
|
|
#define _INCLUDE__LIBC__SELECT_H_
|
|
|
|
/* Genode includes */
|
|
#include <util/reconstructible.h>
|
|
|
|
/* libc includes */
|
|
#include <sys/select.h> /* for fd_set */
|
|
|
|
|
|
namespace Libc {
|
|
|
|
struct Select_cb;
|
|
typedef Genode::Constructible<Libc::Select_cb> Select_handler_cb;
|
|
|
|
struct Select_handler_base
|
|
{
|
|
Select_handler_cb *_select_cb;
|
|
|
|
Select_handler_base();
|
|
~Select_handler_base();
|
|
|
|
/**
|
|
* Traditional select()
|
|
*
|
|
* \returns 0 if no descriptor was ready and schedules for later call
|
|
* of select_ready(), or number of currently ready file
|
|
* descriptors. The latter case does not schedule
|
|
* select_ready().
|
|
*/
|
|
int select(int nfds, fd_set &readfds, fd_set &writefds, fd_set &exceptfds);
|
|
|
|
virtual void select_ready(int nready, fd_set const &, fd_set const &, fd_set const &) = 0;
|
|
|
|
/* \noapi */
|
|
void dispatch_select();
|
|
};
|
|
|
|
template <typename T>
|
|
struct Select_handler : Select_handler_base
|
|
{
|
|
T &obj;
|
|
void (T::*member) (int, fd_set const &, fd_set const &, fd_set const &);
|
|
|
|
Select_handler(T &obj,
|
|
void (T::*member)(int, fd_set const &, fd_set const &, fd_set const &))
|
|
: obj(obj), member(member) { }
|
|
|
|
void select_ready(int nready, fd_set const &readfds,
|
|
fd_set const &writefds, fd_set const &exceptfds) override
|
|
{
|
|
(obj.*member)(nready, readfds, writefds, exceptfds);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif /* _INCLUDE__LIBC__SELECT_H_ */
|