#include <string.h>
#include <assert.h>
+#ifdef ENABLE_EPOLL
+#include <sys/epoll.h>
+#elif ENABLE_KQUEUE
+#include <sys/event.h>
+#include <sys/time.h>
+#endif
+
/* **************************************************************************
* File Reading
* *************************************************************************/
void *timeshift_reader ( void *p )
{
timeshift_t *ts = p;
- int efd, nfds, end, fd = -1, run = 1, wait = -1;
+ int nfds, end, fd = -1, run = 1, wait = -1;
timeshift_file_t *cur_file = NULL;
off_t cur_off = 0;
int cur_speed = 100, keyframe_mode = 0;
timeshift_index_iframe_t *tsi = NULL;
streaming_skip_t *skip = NULL;
time_t last_status = 0;
+#ifdef ENABLE_EPOLL
+ int efd;
+ struct epoll_event ev = { 0 };
+#elif ENABLE_KQUEUE
+ int kfd;
+ struct kevent ke;
+#endif
+#ifdef ENABLE_EPOLL
/* Poll */
- struct epoll_event ev = { 0 };
efd = epoll_create(1);
ev.events = EPOLLIN;
ev.data.fd = ts->rd_pipe.rd;
epoll_ctl(efd, EPOLL_CTL_ADD, ev.data.fd, &ev);
+#elif ENABLE_KQUEUE
+ /* kqueue */
+ kfd = kqueue();
+ EV_SET(&ke, ts->rd_pipe.rd, EVFILT_READ, EV_ADD, 0, 0, NULL);
+ kevent(kfd, &ke, 1, NULL, 0, NULL);
+#endif
/* Output */
while (run) {
/* Wait for data */
if(wait)
+#ifdef ENABLE_EPOLL
nfds = epoll_wait(efd, &ev, 1, wait);
+#elif ENABLE_KQUEUE
+ nfds = kevent(kfd, NULL, 0, &ke, 1, NULL);
+#endif
else
nfds = 0;
wait = -1;
/* Control */
pthread_mutex_lock(&ts->state_mutex);
if (nfds == 1) {
- if (_read_msg(ev.data.fd, &ctrl) > 0) {
+ if (_read_msg(ts->rd_pipe.rd, &ctrl) > 0) {
/* Exit */
if (ctrl->sm_type == SMT_EXIT) {
}
/* Cleanup */
+#ifdef ENABLE_EPOLL
+ close(efd);
+#elif ENABLE_KQUEUE
+ close(kfd);
+#endif
if (fd != -1) close(fd);
if (sm) streaming_msg_free(sm);
if (ctrl) streaming_msg_free(ctrl);