提交 d32cf135 编写于 作者: K Kozlov Dmitry

implemented timerfd for glibc-2.7 or earlier (debian lenny is now welcome)

上级 a7beba7a
PROJECT (accel-pptpd) PROJECT (accel-pptpd C)
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
ADD_SUBDIRECTORY(accel-pptpd) ADD_SUBDIRECTORY(accel-pptpd)
......
...@@ -30,7 +30,6 @@ Requirment ...@@ -30,7 +30,6 @@ Requirment
---------- ----------
1. modern linux distribution 1. modern linux distribution
2. kernel-2.6.25 or later 2. kernel-2.6.25 or later
3. glibc-2.8 or later
4. cmake-2.6 or later 4. cmake-2.6 or later
5. libnl-2.0 or probably later (required for l2tp and builtin shaper) 5. libnl-2.0 or probably later (required for l2tp and builtin shaper)
......
INCLUDE(CheckLibraryExists)
INCLUDE(CheckIncludeFiles)
CHECK_LIBRARY_EXISTS(ssl MD5_Init "" HAVE_SSL)
IF (NOT HAVE_SSL)
MESSAGE(FATAL_ERROR "openssl library not found")
ENDIF (NOT HAVE_SSL)
CHECK_INCLUDE_FILES("openssl/md5.h" HAVE_SSL)
IF (NOT HAVE_SSL)
MESSAGE(FATAL_ERROR "openssl headers not found")
ENDIF (NOT HAVE_SSL)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fvisibility=hidden -D_GNU_SOURCE -DGCC_SPINLOCK -DMEMDEBUG") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fvisibility=hidden -D_GNU_SOURCE -DGCC_SPINLOCK -DMEMDEBUG")
INCLUDE_DIRECTORIES(include) INCLUDE_DIRECTORIES(include)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <sys/signalfd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "triton.h" #include "triton.h"
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#define __aligned_u64 __u64 __attribute__((aligned(8))) #define __aligned_u64 __u64 __attribute__((aligned(8)))
#endif #endif
#include <linux/ppp_defs.h>
#include <linux/if.h> #include <linux/if.h>
#include <linux/if_ppp.h> #include <linux/if_ppp.h>
#include <linux/ppp_defs.h>
#endif #endif
ADD_LIBRARY(log_file SHARED log_file.c) ADD_LIBRARY(log_file SHARED log_file.c)
TARGET_LINK_LIBRARIES(log_file aio rt) TARGET_LINK_LIBRARIES(log_file rt)
INSTALL(TARGETS log_file INSTALL(TARGETS log_file
LIBRARY DESTINATION usr/lib/accel-pptp LIBRARY DESTINATION usr/lib/accel-pptp
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <aio.h> #include <aio.h>
#include <sys/signalfd.h>
#include "log.h" #include "log.h"
#include "events.h" #include "events.h"
......
...@@ -9,6 +9,25 @@ SET(sources_c ...@@ -9,6 +9,25 @@ SET(sources_c
event.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}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS(-DMODULE_PATH="${CMAKE_INSTALL_PREFIX}/usr/lib/accel-pptp") ADD_DEFINITIONS(-DMODULE_PATH="${CMAKE_INSTALL_PREFIX}/usr/lib/accel-pptp")
......
...@@ -2,10 +2,16 @@ ...@@ -2,10 +2,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <sys/timerfd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_TIMERFD
#include <sys/timerfd.h>
#else
#include "timerfd.h"
#endif
#include "triton_p.h" #include "triton_p.h"
...@@ -94,6 +100,7 @@ void *timer_thread(void *arg) ...@@ -94,6 +100,7 @@ void *timer_thread(void *arg)
return NULL; return NULL;
} }
int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_t *ud, int abs_time) 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); 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_ ...@@ -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; t->ctx = (struct _triton_context_t *)ctx->tpd;
else else
t->ctx = (struct _triton_context_t *)default_ctx->tpd; 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) { 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); mempool_free(t);
return -1; 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; ud->tpd = t;
if (triton_timer_mod(ud, abs_time)) { if (triton_timer_mod(ud, abs_time))
close(t->fd); goto out_err;
mempool_free(t);
return -1;
}
spin_lock(&t->ctx->lock); spin_lock(&t->ctx->lock);
list_add_tail(&t->entry, &t->ctx->timers); 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_ ...@@ -131,15 +140,18 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_
t->ud = NULL; t->ud = NULL;
list_del(&t->entry); list_del(&t->entry);
spin_unlock(&t->ctx->lock); spin_unlock(&t->ctx->lock);
close(t->fd); goto out_err;
mempool_free(t);
ud->tpd = NULL;
return -1;
} }
__sync_fetch_and_add(&triton_stat.timer_count, 1); __sync_fetch_and_add(&triton_stat.timer_count, 1);
return 0; 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) int __export triton_timer_mod(struct triton_timer_t *ud,int abs_time)
{ {
......
#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);
}
/* 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 */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册