mirror of
https://github.com/darlinghq/darling-libkqueue.git
synced 2024-11-23 03:39:51 +00:00
kqlite: add initial timerfd support
git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@665 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
parent
72d4ae076e
commit
ac941cc4b2
@ -43,6 +43,7 @@
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -66,6 +67,7 @@ struct kqueue {
|
||||
int epfd; /* epoll */
|
||||
int inofd; /* inotify */
|
||||
int sigfd; /* signalfd */
|
||||
int timefd; /* timerfd */
|
||||
int readfd, writefd; /* epoll descriptors for EVFILT_READ & EVFILT_WRITE */
|
||||
sigset_t sigmask;
|
||||
/* All of the active knotes for each filter. The index in the array matches
|
||||
@ -128,7 +130,7 @@ kq_init(void)
|
||||
struct kqueue *kq;
|
||||
|
||||
#if defined(USE_KQUEUE)
|
||||
if ((kq = malloc(sizeof(*kq))) == NULL)
|
||||
if ((kq = calloc(1, sizeof(*kq))) == NULL)
|
||||
return (NULL);
|
||||
|
||||
kq->kqfd = kqueue();
|
||||
@ -155,14 +157,14 @@ kq_init(void)
|
||||
|
||||
/* Initialize all the event descriptors */
|
||||
sigemptyset(&kq->sigmask);
|
||||
kq->sigfd = kq->inofd = kq->epfd = kq->readfd = kq->writefd = -1;
|
||||
kq->sigfd = signalfd(-1, &kq->sigmask, 0);
|
||||
kq->inofd = inotify_init();
|
||||
kq->epfd = epoll_create(10);
|
||||
kq->readfd = epoll_create(10);
|
||||
kq->writefd = epoll_create(10);
|
||||
kq->timefd = timerfd_create(CLOCK_MONOTONIC, 0);
|
||||
if (kq->sigfd < 0 || kq->inofd < 0 || kq->epfd < 0
|
||||
|| kq->readfd < 0 || kq->writefd < 0)
|
||||
|| kq->readfd < 0 || kq->writefd < 0 || kq->timefd < 0)
|
||||
goto errout;
|
||||
|
||||
/* Add the signalfd descriptor to the epollset */
|
||||
@ -202,12 +204,7 @@ kq_init(void)
|
||||
return (kq);
|
||||
|
||||
errout:
|
||||
free(kq);
|
||||
if (kq->epfd >= 0) close(kq->epfd);
|
||||
if (kq->readfd >= 0) close(kq->readfd);
|
||||
if (kq->writefd >= 0) close(kq->writefd);
|
||||
if (kq->sigfd >= 0) close(kq->sigfd);
|
||||
//FIXME: something like: if (kq->wfd[EVFILT_SIGNAL] >= 0) free(kq->epfd);
|
||||
kq_free(kq);
|
||||
return (NULL);
|
||||
#endif
|
||||
}
|
||||
@ -219,11 +216,21 @@ kq_free(kqueue_t kq)
|
||||
close(kq.kqfd);
|
||||
|
||||
#elif defined(USE_EPOLL)
|
||||
close(kq->sigfd);
|
||||
close(kq->inofd);
|
||||
close(kq->epfd);
|
||||
close(kq->readfd);
|
||||
close(kq->writefd);
|
||||
close(kq->timefd);
|
||||
|
||||
//FIXME: need to free each individual knote
|
||||
for (int i = 0; i < EVFILT_SYSCOUNT; i++)
|
||||
utarray_free(kq->knote[i]);
|
||||
//FIXME: there are a more things to do
|
||||
|
||||
# ifdef KQ_THREADSAFE
|
||||
pthread_mutex_destroy(&kq->kq_mtx);
|
||||
# endif
|
||||
|
||||
#endif
|
||||
free(kq);
|
||||
}
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Mark Heily <mark@heily.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "./lite.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
@ -8,7 +24,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void test_evfilt_write(kqueue_t kq) {
|
||||
struct kevent kev;
|
||||
int sockfd[2];
|
||||
|
Loading…
Reference in New Issue
Block a user