Rename uev_t --> uev_ctx_t and uev_watcher_t --> uev_t

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2013-08-06 02:00:24 +02:00
parent 689b407c8f
commit c69ce87eb8
6 changed files with 61 additions and 61 deletions
+2 -2
View File
@@ -36,7 +36,7 @@
*
* @return The new I/O watcher, or %NULL if invalid pointers or out or memory.
*/
uev_watcher_t *uev_io_create(uev_t *ctx, uev_cb_t *handler, void *data, int fd, uev_dir_t dir)
uev_t *uev_io_create(uev_ctx_t *ctx, uev_cb_t *handler, void *data, int fd, uev_dir_t dir)
{
return uev_watcher_create(ctx, UEV_FILE_TYPE, fd, dir, handler, data);
}
@@ -48,7 +48,7 @@ uev_watcher_t *uev_io_create(uev_t *ctx, uev_cb_t *handler, void *data, int fd,
*
* @return POSIX OK(0) or non-zero with @param errno set.
*/
int uev_io_delete(uev_t *ctx, uev_watcher_t *w)
int uev_io_delete(uev_ctx_t *ctx, uev_t *w)
{
return uev_watcher_delete(ctx, w);
}
+14 -14
View File
@@ -32,9 +32,9 @@
#include "uev.h"
/* Private to libuev, do not use directly! */
uev_watcher_t *uev_watcher_create(uev_t *ctx, uev_type_t type, int fd, uev_dir_t dir, uev_cb_t *cb, void *arg)
uev_t *uev_watcher_create(uev_ctx_t *ctx, uev_type_t type, int fd, uev_dir_t dir, uev_cb_t *cb, void *arg)
{
uev_watcher_t *w;
uev_t *w;
struct epoll_event ev;
if (!ctx || !cb) {
@@ -42,7 +42,7 @@ uev_watcher_t *uev_watcher_create(uev_t *ctx, uev_type_t type, int fd, uev_dir_t
return NULL;
}
w = (uev_watcher_t *)calloc(1, sizeof(*w));
w = (uev_t *)calloc(1, sizeof(*w));
if (!w)
return NULL;
@@ -64,7 +64,7 @@ uev_watcher_t *uev_watcher_create(uev_t *ctx, uev_type_t type, int fd, uev_dir_t
}
/* Private to libuev, do not use directly! */
int uev_watcher_delete(uev_t *ctx, uev_watcher_t *w)
int uev_watcher_delete(uev_ctx_t *ctx, uev_t *w)
{
if (!ctx || !w) {
errno = EINVAL;
@@ -84,18 +84,18 @@ int uev_watcher_delete(uev_t *ctx, uev_watcher_t *w)
/**
* Create an event loop context
*
* @return Returns a new uev_t context, or %NULL on error.
* @return Returns a new uev_ctx_t context, or %NULL on error.
*/
uev_t *uev_ctx_create(void)
uev_ctx_t *uev_ctx_create(void)
{
int fd;
uev_t *ctx;
uev_ctx_t *ctx;
fd = epoll_create(1);
if (fd < 0)
return NULL;
ctx = (uev_t *)calloc(1, sizeof(*ctx));
ctx = (uev_ctx_t *)calloc(1, sizeof(*ctx));
if (!ctx) {
close(fd);
return NULL;
@@ -111,10 +111,10 @@ uev_t *uev_ctx_create(void)
* Destroy an event loop context
* @param ctx A valid libuev context
*/
void uev_ctx_delete(uev_t *ctx)
void uev_ctx_delete(uev_ctx_t *ctx)
{
while (!LIST_EMPTY(&ctx->watchers)) {
uev_watcher_t *w = LIST_FIRST(&ctx->watchers);
uev_t *w = LIST_FIRST(&ctx->watchers);
if (UEV_TIMER_TYPE == w->type)
uev_timer_delete(ctx, w);
@@ -132,10 +132,10 @@ void uev_ctx_delete(uev_t *ctx)
*
* @return POSIX OK(0) upon successful termination of the event loop, or non-zero on error.
*/
int uev_run(uev_t *ctx)
int uev_run(uev_ctx_t *ctx)
{
int result = 0;
uev_watcher_t *w;
uev_t *w;
if (!ctx) {
errno = EINVAL;
@@ -165,7 +165,7 @@ int uev_run(uev_t *ctx)
}
for (i = 0; i < nfds; i++) {
w = (uev_watcher_t *)events[i].data.ptr;
w = (uev_t *)events[i].data.ptr;
if (UEV_TIMER_TYPE == w->type) {
uint64_t exp;
@@ -201,7 +201,7 @@ int uev_run(uev_t *ctx)
* Terminate the event loop
* @param ctx A valid libuev context
*/
void uev_exit(uev_t *ctx)
void uev_exit(uev_ctx_t *ctx)
{
ctx->running = 0;
}
+4 -4
View File
@@ -40,11 +40,11 @@
*
* @return The new watcher, or %NULL with @param errno set on error.
*/
uev_watcher_t *uev_signal_create(uev_t *ctx, uev_cb_t *handler, void *data, int signo)
uev_t *uev_signal_create(uev_ctx_t *ctx, uev_cb_t *handler, void *data, int signo)
{
int fd;
sigset_t mask;
uev_watcher_t *w;
uev_t *w;
sigemptyset(&mask);
fd = signalfd(-1, &mask, SFD_NONBLOCK);
@@ -73,7 +73,7 @@ uev_watcher_t *uev_signal_create(uev_t *ctx, uev_cb_t *handler, void *data, int
*
* @return POSIX OK(0) or non-zero with @param errno set.
*/
int uev_signal_set(uev_t *ctx, uev_watcher_t *w, int signo)
int uev_signal_set(uev_ctx_t *ctx, uev_t *w, int signo)
{
sigset_t mask;
@@ -104,7 +104,7 @@ int uev_signal_set(uev_t *ctx, uev_watcher_t *w, int signo)
*
* @return POSIX OK(0) or non-zero with @param errno set.
*/
int uev_signal_delete(uev_t *ctx, uev_watcher_t *w)
int uev_signal_delete(uev_ctx_t *ctx, uev_t *w)
{
int fd;
+8 -8
View File
@@ -32,16 +32,16 @@
static int in, out;
static int period = 0;
static uev_watcher_t *timer = NULL;
static uev_t *timer = NULL;
static void lifetime_cb(uev_t *ctx, uev_watcher_t *w __attribute__ ((unused)), void *data)
static void lifetime_cb(uev_ctx_t *ctx, uev_t *w __attribute__ ((unused)), void *data)
{
fprintf(stderr, "\nLifetime exceeded %p\n", data);
uev_exit(ctx);
}
/* The pipe watchdog, if it triggers we haven't received data in time. */
static void timeout_cb(uev_t *ctx, uev_watcher_t *w, void *data)
static void timeout_cb(uev_ctx_t *ctx, uev_t *w, void *data)
{
timer = NULL;
fprintf(stderr, "\nTimeout exceeded %p\n", data);
@@ -50,17 +50,17 @@ static void timeout_cb(uev_t *ctx, uev_watcher_t *w, void *data)
uev_exit(ctx);
}
static void periodic_task(uev_t *ctx __attribute__ ((unused)), uev_watcher_t *w __attribute__ ((unused)), void *data __attribute__ ((unused)))
static void periodic_task(uev_ctx_t *ctx __attribute__ ((unused)), uev_t *w __attribute__ ((unused)), void *data __attribute__ ((unused)))
{
fprintf(stderr, "|");
}
static void signal_cb(uev_t *ctx __attribute__ ((unused)), uev_watcher_t *w, void *data __attribute__ ((unused)))
static void signal_cb(uev_ctx_t *ctx __attribute__ ((unused)), uev_t *w, void *data __attribute__ ((unused)))
{
fprintf(stderr, w->signo == SIGINT ? "^Cv" : "^\v");
}
static void pipe_read_cb(uev_t *ctx, uev_watcher_t *w __attribute__ ((unused)), void *data __attribute__ ((unused)))
static void pipe_read_cb(uev_ctx_t *ctx, uev_t *w __attribute__ ((unused)), void *data __attribute__ ((unused)))
{
int cnt;
char msg[50];
@@ -74,7 +74,7 @@ static void pipe_read_cb(uev_t *ctx, uev_watcher_t *w __attribute__ ((unused)),
fprintf(stderr, "%.*s.%d ", cnt, msg, cnt);
}
static void pipe_write_cb(uev_t *ctx, uev_watcher_t *w __attribute__ ((unused)), void *data)
static void pipe_write_cb(uev_ctx_t *ctx, uev_t *w __attribute__ ((unused)), void *data)
{
int cnt = (int)(intptr_t)data;
char *msg = "TESTING";
@@ -94,7 +94,7 @@ static void pipe_write_cb(uev_t *ctx, uev_watcher_t *w __attribute__ ((unused)),
int main(void)
{
int fd[2];
uev_t *ctx = uev_ctx_create();
uev_ctx_t *ctx = uev_ctx_create();
/* Total program execution time */
uev_timer_create(ctx, lifetime_cb, (void *)(intptr_t)2, 4000, 0);
+4 -4
View File
@@ -58,10 +58,10 @@ static struct timespec msec2tspec(int msec)
*
* @return The new watcher, or %NULL with @param errno set on error.
*/
uev_watcher_t *uev_timer_create(uev_t *ctx, uev_cb_t *handler, void *data, int timeout, int period)
uev_t *uev_timer_create(uev_ctx_t *ctx, uev_cb_t *handler, void *data, int timeout, int period)
{
int fd;
uev_watcher_t *w;
uev_t *w;
fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
if (fd < 0)
@@ -90,7 +90,7 @@ uev_watcher_t *uev_timer_create(uev_t *ctx, uev_cb_t *handler, void *data, int t
*
* @return POSIX OK(0) or non-zero with @param errno set on error.
*/
int uev_timer_set(uev_t *ctx, uev_watcher_t *w, int timeout, int period)
int uev_timer_set(uev_ctx_t *ctx, uev_t *w, int timeout, int period)
{
struct itimerspec time;
@@ -118,7 +118,7 @@ int uev_timer_set(uev_t *ctx, uev_watcher_t *w, int timeout, int period)
*
* @return POSIX OK(0) or non-zero with @param errno set on error.
*/
int uev_timer_delete(uev_t *ctx, uev_watcher_t *w)
int uev_timer_delete(uev_ctx_t *ctx, uev_t *w)
{
int fd;
+29 -29
View File
@@ -48,56 +48,56 @@ typedef enum {
} uev_type_t;
/* I/O event watcher */
typedef struct uev_watcher {
LIST_ENTRY(uev_watcher) link; /* For queue.h linked list */
typedef struct uev {
LIST_ENTRY(uev) link; /* For queue.h linked list */
/* Common to all watchers */
uev_type_t type;
int fd;
uev_type_t type;
int fd;
/* Watcher callback with optional argument */
void (*cb)(struct uev *, struct uev_watcher *, void *);
void *arg;
void (*cb)(struct uev *, struct uev *, void *);
void *arg;
/* Timer watchers, time in milliseconds */
int timeout;
int period;
int timeout;
int period;
/* Signal watchers */
int signo;
} uev_watcher_t;
int signo;
} uev_t;
/* Main libuev context type */
typedef struct {
int running;
int efd; /* For epoll() */
LIST_HEAD(, uev_watcher) watchers;
} uev_t;
int running;
int efd; /* For epoll() */
LIST_HEAD(, uev) watchers;
} uev_ctx_t;
/* Generic callback for watchers */
typedef void (uev_cb_t) (uev_t *ctx, uev_watcher_t *w, void *data);
typedef void (uev_cb_t) (uev_ctx_t *ctx, uev_t *w, void *data);
/* Private methods, do not use directly! */
uev_watcher_t *uev_watcher_create(uev_t *ctx, uev_type_t type, int fd, uev_dir_t dir, uev_cb_t *cb, void *data);
int uev_watcher_delete(uev_t *ctx, uev_watcher_t *w);
uev_t *uev_watcher_create(uev_ctx_t *ctx, uev_type_t type, int fd, uev_dir_t dir, uev_cb_t *cb, void *data);
int uev_watcher_delete(uev_ctx_t *ctx, uev_t *w);
/* Public interface */
uev_watcher_t *uev_io_create (uev_t *ctx, uev_cb_t *cb, void *data, int fd, uev_dir_t dir);
int uev_io_delete (uev_t *ctx, uev_watcher_t *w);
uev_t *uev_io_create (uev_ctx_t *ctx, uev_cb_t *cb, void *data, int fd, uev_dir_t dir);
int uev_io_delete (uev_ctx_t *ctx, uev_t *w);
int uev_timer_set (uev_t *ctx, uev_watcher_t *w, int timeout, int period);
uev_watcher_t *uev_timer_create (uev_t *ctx, uev_cb_t *cb, void *data, int timeout, int period);
int uev_timer_delete (uev_t *ctx, uev_watcher_t *w);
int uev_timer_set (uev_ctx_t *ctx, uev_t *w, int timeout, int period);
uev_t *uev_timer_create (uev_ctx_t *ctx, uev_cb_t *cb, void *data, int timeout, int period);
int uev_timer_delete (uev_ctx_t *ctx, uev_t *w);
uev_watcher_t *uev_signal_create (uev_t *ctx, uev_cb_t *handler, void *data, int signo);
int uev_signal_set (uev_t *ctx, uev_watcher_t *w, int signo);
int uev_signal_delete (uev_t *ctx, uev_watcher_t *w);
uev_t *uev_signal_create (uev_ctx_t *ctx, uev_cb_t *handler, void *data, int signo);
int uev_signal_set (uev_ctx_t *ctx, uev_t *w, int signo);
int uev_signal_delete (uev_ctx_t *ctx, uev_t *w);
uev_t *uev_ctx_create (void);
void uev_ctx_delete (uev_t *uev);
uev_ctx_t *uev_ctx_create (void);
void uev_ctx_delete (uev_ctx_t *uev);
int uev_run (uev_t *ctx);
void uev_exit (uev_t *ctx);
int uev_run (uev_ctx_t *ctx);
void uev_exit (uev_ctx_t *ctx);
#endif /* LIBUEV_UEV_H_ */