#include "config.h"
#include "unix-std.h"
+#include "contrib/libev/ev.h"
/*
* OpenBSD fix
int cdb_fd; /* file descriptor */
char *filename; /* file name */
time_t mtime; /* mtime of cdb file */
- struct event *check_timer_ev; /* event structure for checking cdb for modifications */
- struct timeval *check_timer_tv;
+ struct ev_loop *loop;
+ ev_stat stat_ev; /* event structure for checking cdb for modifications */
+ ev_tstamp check_ts;
/* private members */
unsigned cdb_fsize; /* datafile size */
unsigned cdb_dend; /* end of data ptr */
#define cdb_fileno(c) ((c)->cdb_fd)
int cdb_init(struct cdb *cdbp, int fd);
-void cdb_add_timer(struct cdb *cdbp, unsigned seconds);
+void cdb_add_timer(struct cdb *cdbp, EV_P_ ev_tstamp seconds);
void cdb_free(struct cdb *cdbp);
int cdb_read(const struct cdb *cdbp, void *buf, unsigned len, unsigned pos);
}
cdbp->cdb_fsize = 0;
- if (cdbp->check_timer_ev) {
- evtimer_del (cdbp->check_timer_ev);
- g_free (cdbp->check_timer_ev);
- g_free (cdbp->check_timer_tv);
+ if (cdbp->loop) {
+ ev_stat_stop (cdbp->loop, &cdbp->stat_ev);
}
}
}
static void
-cdb_timer_callback (int fd, short what, gpointer ud)
+cdb_timer_callback (EV_P_ ev_stat *w, int revents)
{
- struct cdb *cdbp = ud;
+ struct cdb *cdbp = w->data;
gint nfd;
- struct stat st;
/* Check cdb file for modifications */
- if (stat (cdbp->filename, &st) != -1) {
- if (st.st_mtime > cdbp->mtime) {
- if ((nfd = open (cdbp->filename, O_RDONLY)) != -1) {
- if (cdbp->cdb_mem) {
+ if ((nfd = open (cdbp->filename, O_RDONLY)) != -1) {
+ if (cdbp->cdb_mem) {
#ifdef _WIN32
- UnmapViewOfFile((void*) cdbp->cdb_mem);
+ UnmapViewOfFile((void*) cdbp->cdb_mem);
#else
- munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize);
+ munmap ((void*) cdbp->cdb_mem, cdbp->cdb_fsize);
#endif /* _WIN32 */
- cdbp->cdb_mem = NULL;
- }
- (void)close (cdbp->cdb_fd);
- cdbp->cdb_fsize = 0;
- (void)cdb_init (cdbp, nfd);
- }
+ cdbp->cdb_mem = NULL;
}
+ (void)close (cdbp->cdb_fd);
+ cdbp->cdb_fsize = 0;
+ (void)cdb_init (cdbp, nfd);
}
-
- evtimer_add (cdbp->check_timer_ev, cdbp->check_timer_tv);
}
void
-cdb_add_timer(struct cdb *cdbp, unsigned seconds)
+cdb_add_timer (struct cdb *cdbp, EV_P_ ev_tstamp seconds)
{
- cdbp->check_timer_ev = g_malloc (sizeof (struct event));
- cdbp->check_timer_tv = g_malloc (sizeof (struct timeval));
-
- cdbp->check_timer_tv->tv_sec = seconds;
- cdbp->check_timer_tv->tv_usec = 0;
-
- evtimer_set (cdbp->check_timer_ev, cdb_timer_callback, cdbp);
- evtimer_add (cdbp->check_timer_ev, cdbp->check_timer_tv);
+ cdbp->loop = loop;
+ ev_stat_init (&cdbp->stat_ev, cdb_timer_callback, cdbp->filename, seconds);
+ cdbp->stat_ev.data = cdbp;
+ ev_stat_start (EV_A_ &cdbp->stat_ev);
}
* limitations under the License.
*/
#include "config.h"
-#include "rspamd.h"
#include "keypairs_cache.h"
#include "keypair_private.h"
+#include "libutil/util.h"
#include "hash.h"
struct rspamd_keypair_elt {
struct rspamd_dns_resolver *resolver; /**< DNS resolver */
struct ev_loop *event_loop; /**< Event base */
- struct event timeout_ev; /**< Global task timeout */
- struct event *guard_ev; /**< Event for input sanity guard */
+ struct ev_timer timeout_ev; /**< Global task timeout */
+ struct ev_io *guard_ev; /**< Event for input sanity guard */
gpointer checkpoint; /**< Opaque checkpoint data */
ucl_object_t *settings; /**< Settings applied to task */
struct redis_stat_ctx *ctx;
struct rspamd_task *task;
struct upstream *selected;
- struct event timeout_event;
+ ev_timer timeout_event;
GArray *results;
struct rspamd_statfile_config *stcf;
gchar *redis_object_expanded;
rt->has_event = FALSE;
/* Stop timeout */
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_stop (rt->task->event_loop, &rt->timeout_event);
}
if (rt->redis) {
}
static void
-rspamd_redis_timeout (gint fd, short what, gpointer d)
+rspamd_redis_timeout (EV_P_ ev_timer *w, int revents)
{
- struct redis_stat_runtime *rt = REDIS_RUNTIME (d);
+ struct redis_stat_runtime *rt = REDIS_RUNTIME (w->data);
struct rspamd_task *task;
redisAsyncContext *redis;
{
struct redis_stat_runtime *rt = REDIS_RUNTIME (p);
rspamd_fstring_t *query;
- struct timeval tv;
gint ret;
const gchar *learned_key = "learns";
rspamd_session_add_event (task->s, rspamd_redis_fin, rt, M);
rt->has_event = TRUE;
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_again (task->event_loop, &rt->timeout_event);
+ }
+ else {
+ ev_timer_init (&rt->timeout_event, rspamd_redis_timeout,
+ rt->ctx->timeout, 0.);
+ ev_timer_start (task->event_loop, &rt->timeout_event);
}
- event_set (&rt->timeout_event, -1, EV_TIMEOUT, rspamd_redis_timeout, rt);
- event_base_set (task->event_loop, &rt->timeout_event);
- double_to_tv (rt->ctx->timeout, &tv);
- event_add (&rt->timeout_event, &tv);
query = rspamd_redis_tokens_to_query (task, rt, tokens,
rt->ctx->new_schema ? "HGET" : "HMGET",
struct redis_stat_runtime *rt = REDIS_RUNTIME (runtime);
redisAsyncContext *redis;
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_stop (task->event_loop, &rt->timeout_event);
}
if (rt->redis) {
rt->has_event = TRUE;
/* Set timeout */
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_again (task->event_loop, &rt->timeout_event);
+ }
+ else {
+ ev_timer_init (&rt->timeout_event, rspamd_redis_timeout,
+ rt->ctx->timeout, 0.);
+ ev_timer_start (task->event_loop, &rt->timeout_event);
}
- event_set (&rt->timeout_event, -1, EV_TIMEOUT, rspamd_redis_timeout, rt);
- event_base_set (task->event_loop, &rt->timeout_event);
- double_to_tv (rt->ctx->timeout, &tv);
- event_add (&rt->timeout_event, &tv);
return TRUE;
}
struct redis_stat_runtime *rt = REDIS_RUNTIME (runtime);
redisAsyncContext *redis;
- if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) {
- event_del (&rt->timeout_event);
+ if (ev_is_active (&rt->timeout_event)) {
+ ev_timer_stop (task->event_loop, &rt->timeout_event);
}
if (rt->redis) {
# Librspamd-util
SET(LIBRSPAMDUTILSRC
${CMAKE_CURRENT_SOURCE_DIR}/addr.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/libev_helper.c
${CMAKE_CURRENT_SOURCE_DIR}/aio_event.c
${CMAKE_CURRENT_SOURCE_DIR}/bloom.c
${CMAKE_CURRENT_SOURCE_DIR}/expression.c
return (((gint32)(guint16)((guint32)r + 0x8000) - 0x8000) == 0);
}
-#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000000UL
-struct ev_loop *
-event_get_base (struct event *ev)
-{
- return ev->ev_base;
-}
-#endif
-
-int
-rspamd_event_pending (struct event *ev, short what)
-{
- if (ev->ev_base == NULL) {
- return 0;
- }
-
- return event_pending (ev, what, NULL);
-}
-
int
rspamd_file_xopen (const char *fname, int oflags, guint mode,
gboolean allow_symlink)
*/
gboolean rspamd_constant_memcmp (const guchar *a, const guchar *b, gsize len);
-
-/* Avoid stupidity in libevent > 1.4 */
-int rspamd_event_pending (struct event *ev, short what);
-
/**
* Open file without following symlinks or special stuff
* @param fname filename
else {
cdb = g_malloc (sizeof (struct cdb));
cdb->filename = g_strdup (filename);
- cdb->check_timer_ev = NULL;
- cdb->check_timer_tv = NULL;
if (cdb_init (cdb, fd) == -1) {
msg_warn ("cannot open cdb: %s, %s", filename, strerror (errno));
lua_pushnil (L);
}
else {
+ cdb_add_timer (cdb, ev_default_loop (0), CDB_REFRESH_TIME);
pcdb = lua_newuserdata (L, sizeof (struct cdb *));
rspamd_lua_setclass (L, "rspamd{cdb}", -1);
*pcdb = cdb;
lua_error (L);
return 1;
}
- /*
- * XXX: this code is placed here because event_loop is called inside workers, so start
- * monitoring on first check, not on creation
- */
- if (cdb->check_timer_ev == NULL) {
- cdb_add_timer (cdb, CDB_REFRESH_TIME);
- }
what = luaL_checkstring (L, 2);
if (cdb_find (cdb, what, strlen (what)) > 0) {