sched: rework file handling API

Replace SCH_*InputFileHandler() functions with more general
SCH_*FileHandler(), where events are specified as a new parameter and
which will later support other file events, e.g. file ready for ouput
and exception.

The file handlers have two new parameters: file descriptor and event.
This commit is contained in:
Miroslav Lichvar
2016-06-16 16:47:40 +02:00
parent aeb57a36b2
commit 0a10545314
7 changed files with 49 additions and 38 deletions

22
sched.c
View File

@@ -166,12 +166,14 @@ SCH_Finalise(void) {
/* ================================================== */
void
SCH_AddInputFileHandler
(int fd, SCH_FileHandler handler, SCH_ArbitraryArgument arg)
SCH_AddFileHandler
(int fd, int events, SCH_FileHandler handler, SCH_ArbitraryArgument arg)
{
FileHandlerEntry *ptr;
assert(initialised);
assert(events);
assert(fd >= 0);
if (fd >= FD_SETSIZE)
LOG_FATAL(LOGF_Scheduler, "Too many file descriptors");
@@ -202,7 +204,7 @@ SCH_AddInputFileHandler
/* ================================================== */
void
SCH_RemoveInputFileHandler(int fd)
SCH_RemoveFileHandler(int fd)
{
int fds_left, fd_to_check;
@@ -231,6 +233,18 @@ SCH_RemoveInputFileHandler(int fd)
/* ================================================== */
void
SCH_SetFileHandlerEvents(int fd, int events)
{
FileHandlerEntry *ptr;
assert(events);
ptr = ARR_GetElement(file_handlers, fd);
ptr->events = events;
}
/* ================================================== */
void
SCH_GetLastEventTime(struct timeval *cooked, double *err, struct timeval *raw)
{
@@ -533,7 +547,7 @@ dispatch_filehandlers(int nfh, fd_set *fhs)
/* This descriptor can be read from, dispatch its handler */
ptr = (FileHandlerEntry *)ARR_GetElement(file_handlers, fh);
(ptr->handler)(ptr->arg);
(ptr->handler)(fh, SCH_FILE_INPUT, ptr->arg);
/* Decrement number of readable files still to find */
--nfh;