mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 08:35:07 -05:00
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:
22
sched.c
22
sched.c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user