TwiceAsNice
2019-02-18
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include "eventloop.h"
Classes | |
struct | CB |
struct | TF |
struct | WP |
Macros | |
#define | EPOCHDT(tp) /* ms from epoch to timeval *tp */ (((tp)->tv_usec) / 1000.0 + ((tp)->tv_sec) * 1000.0) |
Functions | |
static void | runWorkProc (void) |
static void | callCallback (fd_set *rfdp) |
static void | checkTimer () |
static void | oneLoop (void) |
static void | deferTO (void *p) |
void | eventLoop () |
Main calls this when ready to hand over control. More... | |
int | deferLoop (int maxms, int *flagp) |
int | deferLoop0 (int maxms, int *flagp) |
int | addCallback (int fd, CBF *fp, void *ud) |
Register a new callback, fp, to be called with ud as argument when fd is ready. More... | |
void | rmCallback (int cid) |
Remove a callback function. More... | |
int | addTimer (int ms, TCF *fp, void *ud) |
Register a new timer function, fp, to be called with ud as argument after ms. More... | |
void | rmTimer (int timer_id) |
Remove the timer with the given id, as returned from addTimer(). More... | |
int | addWorkProc (WPF *fp, void *ud) |
Add a new work procedure, fp, to be called with ud when nothing else to do. More... | |
void | rmWorkProc (int wid) |
Remove the work procedure with the given id, as returned from addWorkProc(). More... | |
Variables | |
static CB * | cback |
static int | ncback |
static int | ncbinuse |
static int | lastcb |
static TF * | timef |
static int | ntimef |
static int | tid |
static WP * | wproc |
static int | nwproc |
static int | nwpinuse |
static int | lastwp |
#define EPOCHDT | ( | tp | ) | /* ms from epoch to timeval *tp */ (((tp)->tv_usec) / 1000.0 + ((tp)->tv_sec) * 1000.0) |
int addCallback | ( | int | fd, |
CBF * | fp, | ||
void * | ud | ||
) |
Register a new callback, fp, to be called with ud as argument when fd is ready.
fd | file descriptor. |
fp | a pointer to the callback function. |
ud | a pointer to be passed to the callback function when called. |
int addTimer | ( | int | ms, |
TCF * | fp, | ||
void * | ud | ||
) |
Register a new timer function, fp, to be called with ud as argument after ms.
Add to list in order of decreasing time from epoch, ie, last entry runs soonest. The timer will only invoke the callback function once. You need to call addTimer again if you want to repeat the process.
ms | timer period in milliseconds. |
fp | a pointer to the callback function. |
ud | a pointer to be passed to the callback function when called. |
int addWorkProc | ( | WPF * | fp, |
void * | ud | ||
) |
Add a new work procedure, fp, to be called with ud when nothing else to do.
fp | a pointer to the work procedure callback function. |
ud | a pointer to be passed to the callback function when called. |
|
static |
|
static |
int deferLoop | ( | int | maxms, |
int * | flagp | ||
) |
int deferLoop0 | ( | int | maxms, |
int * | flagp | ||
) |
|
static |
void eventLoop | ( | ) |
Main calls this when ready to hand over control.
|
static |
void rmCallback | ( | int | cid | ) |
Remove a callback function.
cid | the callback ID returned from addCallback(). |
void rmTimer | ( | int | tid | ) |
Remove the timer with the given id, as returned from addTimer().
tid | the timer callback ID returned from addTimer(). |
void rmWorkProc | ( | int | wid | ) |
Remove the work procedure with the given id, as returned from addWorkProc().
wid | the work procedure callback ID returned from addWorkProc(). |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |