init_controller_worker, /* Init function */
start_controller_worker, /* Start function */
RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
- SOCK_STREAM, /* TCP socket */
+ RSPAMD_WORKER_SOCKET_TCP, /* TCP socket */
RSPAMD_WORKER_VER /* Version info */
};
/*
init_fuzzy, /* Init function */
start_fuzzy, /* Start function */
RSPAMD_WORKER_HAS_SOCKET,
- SOCK_DGRAM, /* UDP socket */
+ RSPAMD_WORKER_SOCKET_UDP, /* UDP socket */
RSPAMD_WORKER_VER /* Version info */
};
{
struct rspamd_fuzzy_storage_ctx *ctx = ud;
GList *cur;
- gint listen_socket;
+ struct rspamd_worker_listen_socket *ls;
struct event *accept_event;
gdouble next_check;
/* Start listening */
cur = worker->cf->listen_socks;
while (cur) {
- listen_socket = GPOINTER_TO_INT (cur->data);
- if (listen_socket != -1) {
+ ls = cur->data;
+
+ if (ls->fd != -1) {
accept_event = g_slice_alloc0 (sizeof (struct event));
- event_set (accept_event, listen_socket, EV_READ | EV_PERSIST,
+ event_set (accept_event, ls->fd, EV_READ | EV_PERSIST,
accept_fuzzy_socket, worker);
event_base_set (ctx->ev_base, accept_event);
event_add (accept_event, NULL);
worker->accept_events = g_list_prepend (worker->accept_events,
accept_event);
}
+
cur = g_list_next (cur);
}
init_hs_helper, /* Init function */
start_hs_helper, /* Start function */
RSPAMD_WORKER_UNIQUE|RSPAMD_WORKER_KILLABLE|RSPAMD_WORKER_ALWAYS_START,
- SOCK_STREAM, /* TCP socket */
+ RSPAMD_WORKER_SOCKET_NONE, /* No socket */
RSPAMD_WORKER_VER /* Version info */
};
struct event_base *ev_base;
struct event *accept_event;
GList *cur;
- gint listen_socket;
+ struct rspamd_worker_listen_socket *ls;
#ifdef WITH_PROFILER
extern void _start (void), etext (void);
/* Accept all sockets */
if (accept_handler) {
cur = worker->cf->listen_socks;
+
while (cur) {
- listen_socket = GPOINTER_TO_INT (cur->data);
- if (listen_socket != -1) {
+ ls = cur->data;
+
+ if (ls->fd != -1) {
accept_event = g_slice_alloc0 (sizeof (struct event));
- event_set (accept_event, listen_socket, EV_READ | EV_PERSIST,
+ event_set (accept_event, ls->fd, EV_READ | EV_PERSIST,
accept_handler, worker);
event_base_set (ev_base, accept_event);
event_add (accept_event, NULL);
worker->accept_events = g_list_prepend (worker->accept_events,
accept_event);
}
+
cur = g_list_next (cur);
}
}
init_log_helper, /* Init function */
start_log_helper, /* Start function */
RSPAMD_WORKER_UNIQUE | RSPAMD_WORKER_KILLABLE,
- SOCK_STREAM, /* TCP socket */
- RSPAMD_WORKER_VER /* Version info */
+ RSPAMD_WORKER_SOCKET_NONE, /* No socket */
+ RSPAMD_WORKER_VER /* Version info */
};
static const guint64 rspamd_log_helper_magic = 0x1090bb46aaa74c9aULL;
void start_lua_worker (struct rspamd_worker *worker);
worker_t lua_worker = {
- "lua", /* Name */
- init_lua_worker, /* Init function */
- start_lua_worker, /* Start function */
+ "lua", /* Name */
+ init_lua_worker, /* Init function */
+ start_lua_worker, /* Start function */
RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
- SOCK_STREAM, /* TCP socket */
- RSPAMD_WORKER_VER /* Version info */
+ RSPAMD_WORKER_SOCKET_TCP, /* TCP socket */
+ RSPAMD_WORKER_VER /* Version info */
};
static const guint64 rspamd_lua_ctx_magic = 0x8055e2652aacf96eULL;
}
static GList *
-create_listen_socket (GPtrArray *addrs, guint cnt, gint listen_type)
+create_listen_socket (GPtrArray *addrs, guint cnt,
+ enum rspamd_worker_socket_type listen_type)
{
GList *result = NULL;
gint fd;
guint i;
- gpointer p;
+ struct rspamd_worker_listen_socket *ls;
g_ptr_array_sort (addrs, rspamd_inet_address_compare_ptr);
for (i = 0; i < cnt; i ++) {
- fd = rspamd_inet_address_listen (g_ptr_array_index (addrs, i),
- listen_type, TRUE);
- if (fd != -1) {
- p = GINT_TO_POINTER (fd);
- result = g_list_prepend (result, p);
+
+ if (listen_type & RSPAMD_WORKER_SOCKET_TCP) {
+ fd = rspamd_inet_address_listen (g_ptr_array_index (addrs, i),
+ SOCK_STREAM, TRUE);
+ if (fd != -1) {
+ ls = g_slice_alloc0 (sizeof (*ls));
+ ls->addr = g_ptr_array_index (addrs, i);
+ ls->fd = fd;
+ ls->type = RSPAMD_WORKER_SOCKET_TCP;
+ result = g_list_prepend (result, ls);
+ }
+ }
+ if (listen_type & RSPAMD_WORKER_SOCKET_UDP) {
+ fd = rspamd_inet_address_listen (g_ptr_array_index (addrs, i),
+ SOCK_DGRAM, TRUE);
+ if (fd != -1) {
+ ls = g_slice_alloc0 (sizeof (*ls));
+ ls->addr = g_ptr_array_index (addrs, i);
+ ls->fd = fd;
+ ls->type = RSPAMD_WORKER_SOCKET_TCP;
+ result = g_list_prepend (result, ls);
+ }
}
}
key = make_listen_key (bcf);
if ((p =
g_hash_table_lookup (listen_sockets,
- GINT_TO_POINTER (key))) == NULL) {
+ GINT_TO_POINTER (key))) == NULL) {
if (!bcf->is_systemd) {
/* Create listen socket */
RSPAMD_WORKER_ALWAYS_START = (1 << 4),
};
+enum rspamd_worker_socket_type {
+ RSPAMD_WORKER_SOCKET_NONE = 0,
+ RSPAMD_WORKER_SOCKET_TCP = (1 << 0),
+ RSPAMD_WORKER_SOCKET_UDP = (1 << 1),
+};
+
+struct rspamd_worker_listen_socket {
+ const rspamd_inet_addr_t *addr;
+ gint fd;
+ enum rspamd_worker_socket_type type;
+};
+
typedef struct worker_s {
const gchar *name;
gpointer (*worker_init_func)(struct rspamd_config *cfg);
void (*worker_start_func)(struct rspamd_worker *worker);
enum rspamd_worker_flags flags;
- gint listen_type;
+ enum rspamd_worker_socket_type listen_type;
guint worker_version;
guint64 rspamd_version;
const gchar *rspamd_features;
init_rspamd_proxy, /* Init function */
start_rspamd_proxy, /* Start function */
RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
- SOCK_STREAM, /* TCP socket */
+ RSPAMD_WORKER_SOCKET_TCP, /* TCP socket */
RSPAMD_WORKER_VER
};
init_smtp_proxy, /* Init function */
start_smtp_proxy, /* Start function */
RSPAMD_WORKER_HAS_SOCKET | RSPAMD_WORKER_KILLABLE,
- SOCK_STREAM, /* TCP socket */
+ RSPAMD_WORKER_SOCKET_TCP, /* TCP socket */
RSPAMD_WORKER_VER /* Version info */
};
init_worker, /* Init function */
start_worker, /* Start function */
RSPAMD_WORKER_HAS_SOCKET|RSPAMD_WORKER_KILLABLE,
- SOCK_STREAM, /* TCP socket */
+ RSPAMD_WORKER_SOCKET_TCP, /* TCP socket */
RSPAMD_WORKER_VER /* Version info */
};