summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-10-15 16:52:27 +0400
committerKozlov Dmitry <dima@server>2010-10-15 18:18:35 +0400
commitd32cf13525153b9bb961a72cded215e9866e78bd (patch)
treed5d465a5729c87843894f6eb0c91361183f93e56 /accel-pptpd/triton
parenta7beba7a9253b002c3be1fdd54420422a79cf96e (diff)
downloadaccel-ppp-d32cf13525153b9bb961a72cded215e9866e78bd.tar.gz
accel-ppp-d32cf13525153b9bb961a72cded215e9866e78bd.zip
implemented timerfd for glibc-2.7 or earlier (debian lenny is now welcome)
Diffstat (limited to 'accel-pptpd/triton')
-rw-r--r--accel-pptpd/triton/CMakeLists.txt19
-rw-r--r--accel-pptpd/triton/timer.c36
-rw-r--r--accel-pptpd/triton/timerfd.c19
-rw-r--r--accel-pptpd/triton/timerfd.h60
4 files changed, 122 insertions, 12 deletions
diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt
index 8e9fd35..e9133ae 100644
--- a/accel-pptpd/triton/CMakeLists.txt
+++ b/accel-pptpd/triton/CMakeLists.txt
@@ -9,6 +9,25 @@ SET(sources_c
event.c
)
+INCLUDE(CheckFunctionExists)
+CHECK_FUNCTION_EXISTS(timerfd_create HAVE_TIMERFD)
+
+IF (HAVE_TIMERFD)
+ ADD_DEFINITIONS(-DHAVE_TIMERFD)
+ELSE (HAVE_TIMERFD)
+ INCLUDE (CheckCSourceCompiles)
+ CHECK_C_SOURCE_COMPILES("
+ #include <sys/syscall.h>
+ int main()
+ {
+ syscall(SYS_timerfd_create);
+ }" HAVE_SYSCALL)
+ IF (NOT HAVE_SYSCALL)
+ MESSAGE(FATAL_ERROR "Your system is too old and is not supported by accel-pptp, sorry...")
+ ENDIF (NOT HAVE_SYSCALL)
+ SET(sources_c ${sources_c} timerfd.c)
+ENDIF (HAVE_TIMERFD)
+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS(-DMODULE_PATH="${CMAKE_INSTALL_PREFIX}/usr/lib/accel-pptp")
diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c
index cbf2b13..43cb56f 100644
--- a/accel-pptpd/triton/timer.c
+++ b/accel-pptpd/triton/timer.c
@@ -2,10 +2,16 @@
#include <stdlib.h>
#include <sys/time.h>
#include <sys/epoll.h>
-#include <sys/timerfd.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
+
+#ifdef HAVE_TIMERFD
+#include <sys/timerfd.h>
+#else
+#include "timerfd.h"
+#endif
#include "triton_p.h"
@@ -94,6 +100,7 @@ void *timer_thread(void *arg)
return NULL;
}
+
int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_t *ud, int abs_time)
{
struct _triton_timer_t *t = mempool_alloc(timer_pool);
@@ -106,20 +113,22 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_
t->ctx = (struct _triton_context_t *)ctx->tpd;
else
t->ctx = (struct _triton_context_t *)default_ctx->tpd;
- t->fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
+ t->fd = timerfd_create(CLOCK_MONOTONIC, 0);
if (t->fd < 0) {
- triton_log_error("timer:timerfd_create: %s" ,strerror(errno));
+ triton_log_error("timer:timerfd_create: %s", strerror(errno));
mempool_free(t);
return -1;
}
+
+ if (fcntl(t->fd, F_SETFL, O_NONBLOCK)) {
+ triton_log_error("timer: failed to set nonblocking mode: %s\n", strerror(errno));
+ goto out_err;
+ }
ud->tpd = t;
- if (triton_timer_mod(ud, abs_time)) {
- close(t->fd);
- mempool_free(t);
- return -1;
- }
+ if (triton_timer_mod(ud, abs_time))
+ goto out_err;
spin_lock(&t->ctx->lock);
list_add_tail(&t->entry, &t->ctx->timers);
@@ -131,15 +140,18 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_
t->ud = NULL;
list_del(&t->entry);
spin_unlock(&t->ctx->lock);
- close(t->fd);
- mempool_free(t);
- ud->tpd = NULL;
- return -1;
+ goto out_err;
}
__sync_fetch_and_add(&triton_stat.timer_count, 1);
return 0;
+
+out_err:
+ ud->tpd = NULL;
+ close(t->fd);
+ mempool_free(t);
+ return -1;
}
int __export triton_timer_mod(struct triton_timer_t *ud,int abs_time)
{
diff --git a/accel-pptpd/triton/timerfd.c b/accel-pptpd/triton/timerfd.c
new file mode 100644
index 0000000..b026258
--- /dev/null
+++ b/accel-pptpd/triton/timerfd.c
@@ -0,0 +1,19 @@
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+#include "timerfd.h"
+
+int timerfd_create (clockid_t __clock_id, int __flags)
+{
+ return syscall(SYS_timerfd_create, __clock_id, __flags);
+}
+
+
+int timerfd_settime (int __ufd, int __flags,
+ __const struct itimerspec *__utmr,
+ struct itimerspec *__otmr)
+{
+ return syscall(SYS_timerfd_settime, __ufd, __flags, __utmr, __otmr);
+}
+
diff --git a/accel-pptpd/triton/timerfd.h b/accel-pptpd/triton/timerfd.h
new file mode 100644
index 0000000..c1bb06f
--- /dev/null
+++ b/accel-pptpd/triton/timerfd.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2008 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _SYS_TIMERFD_H
+#define _SYS_TIMERFD_H 1
+
+#include <time.h>
+
+
+/* Bits to be set in the FLAGS parameter of `timerfd_create'. */
+enum
+ {
+ TFD_CLOEXEC = 02000000,
+#define TFD_CLOEXEC TFD_CLOEXEC
+ TFD_NONBLOCK = 04000
+#define TFD_NONBLOCK TFD_NONBLOCK
+ };
+
+
+/* Bits to be set in the FLAGS parameter of `timerfd_settime'. */
+enum
+ {
+ TFD_TIMER_ABSTIME = 1 << 0
+#define TFD_TIMER_ABSTIME TFD_TIMER_ABSTIME
+ };
+
+
+__BEGIN_DECLS
+
+/* Return file descriptor for new interval timer source. */
+extern int timerfd_create (clockid_t __clock_id, int __flags) __THROW;
+
+/* Set next expiration time of interval timer source UFD to UTMR. If
+ FLAGS has the TFD_TIMER_ABSTIME flag set the timeout value is
+ absolute. Optionally return the old expiration time in OTMR. */
+extern int timerfd_settime (int __ufd, int __flags,
+ __const struct itimerspec *__utmr,
+ struct itimerspec *__otmr) __THROW;
+
+/* Return the next expiration time of UFD. */
+extern int timerfd_gettime (int __ufd, struct itimerspec *__otmr) __THROW;
+
+__END_DECLS
+
+#endif /* sys/timerfd.h */