Handle miliseconds using a common macro.
}
/* Fill timeout */
- req->tv.tv_sec = resolver->request_timeout / 1000;
- req->tv.tv_usec = (resolver->request_timeout - req->tv.tv_sec * 1000) * 1000;
+ msec_to_tv (resolver->request_timeout, &req->tv);
-
/* Now send request to server */
r = send_dns_request (req);
new->request_timeout = cfg->dns_timeout;
new->max_retransmits = cfg->dns_retransmits;
new->max_errors = cfg->dns_throttling_errors;
- new->throttling_time.tv_sec = cfg->dns_throttling_time / 1000;
- new->throttling_time.tv_usec = (cfg->dns_throttling_time - new->throttling_time.tv_sec * 1000) * 1000;
+ msec_to_tv (cfg->dns_throttling_time, &new->throttling_time);
if (cfg->nameservers == NULL) {
/* Parse resolv.conf */
hostbuf[hostmax - 1] = '\0';
rspamd_snprintf (greetingbuf, sizeof (greetingbuf), "%d rspamd version %s LMTP on %s Ready\r\n", LMTP_OK, RVERSION, hostbuf);
- io_tv.tv_sec = WORKER_IO_TIMEOUT;
+ io_tv.tv_sec = 60000;
io_tv.tv_usec = 0;
gperf_profiler_init (worker->srv->cfg, "lmtp");
#define SOFT_SHUTDOWN_TIME 10
/* Default metric name */
#define DEFAULT_METRIC "default"
-/* 60 seconds for worker's IO */
-#define WORKER_IO_TIMEOUT 60
+
/* Spam subject */
#define SPAM_SUBJECT "*** SPAM *** "
#define DEFAULT_UPSTREAM_DEAD_TIME 300
#define DEFAULT_UPSTREAM_MAXERRORS 10
-#define IO_TIMEOUT 5
+#define DEFAULT_IO_TIMEOUT 500
#define DEFAULT_PORT 11335
struct storage_server {
gint32 min_bytes;
gint32 min_height;
gint32 min_width;
+ guint32 io_timeout;
};
struct fuzzy_client_session {
register_module_opt ("fuzzy_check", "min_height", MODULE_OPT_TYPE_UINT);
register_module_opt ("fuzzy_check", "min_width", MODULE_OPT_TYPE_UINT);
register_module_opt ("fuzzy_check", "min_symbols", MODULE_OPT_TYPE_UINT);
+ register_module_opt ("fuzzy_check", "timeout", MODULE_OPT_TYPE_TIME);
return 0;
}
else {
fuzzy_module_ctx->min_width = 0;
}
+ if ((value = get_module_opt (cfg, "fuzzy_check", "timeout")) != NULL) {
+ fuzzy_module_ctx->io_timeout = parse_time (value, TIME_SECONDS);
+ }
+ else {
+ fuzzy_module_ctx->io_timeout = DEFAULT_IO_TIMEOUT;
+ }
if ((value = get_module_opt (cfg, "fuzzy_check", "mime_types")) != NULL) {
fuzzy_module_ctx->mime_types = parse_mime_types (value);
}
/* Create session for a socket */
session = memory_pool_alloc (task->task_pool, sizeof (struct fuzzy_client_session));
event_set (&session->ev, sock, EV_WRITE, fuzzy_io_callback, session);
- session->tv.tv_sec = IO_TIMEOUT;
- session->tv.tv_usec = 0;
+ msec_to_tv (fuzzy_module_ctx->io_timeout, &session->tv);
session->state = 0;
session->h = h;
session->task = task;
/* Socket is made, create session */
s = memory_pool_alloc (session->session_pool, sizeof (struct fuzzy_learn_session));
event_set (&s->ev, sock, EV_WRITE, fuzzy_learn_callback, s);
- s->tv.tv_sec = IO_TIMEOUT;
- s->tv.tv_usec = 0;
+ msec_to_tv (fuzzy_module_ctx->io_timeout, &s->tv);
s->task = task;
s->h = memory_pool_alloc (session->session_pool, sizeof (fuzzy_hash_t));
memcpy (s->h, h, sizeof (fuzzy_hash_t));
tv = memory_pool_alloc (session->pool, sizeof (struct timeval));
if (session->ctx->delay_jitter != 0) {
jitter = g_random_int_range (0, session->ctx->delay_jitter);
- tv->tv_sec = (session->ctx->smtp_delay + jitter) / 1000;
- tv->tv_usec = (session->ctx->smtp_delay + jitter - tv->tv_sec * 1000) * 1000;
+ msec_to_tv (session->ctx->smtp_delay + jitter, tv);
}
else {
- tv->tv_sec = session->ctx->smtp_delay / 1000;
- tv->tv_usec = (session->ctx->smtp_delay - tv->tv_sec * 1000) * 1000;
+ msec_to_tv (session->ctx->smtp_delay, tv);
}
evtimer_set (tev, smtp_delay_handler, session);
gchar *value;
/* Init timeval */
- ctx->smtp_timeout.tv_sec = ctx->smtp_timeout_raw / 1000;
- ctx->smtp_timeout.tv_usec = (ctx->smtp_timeout_raw - ctx->smtp_timeout.tv_sec * 1000) * 1000;
+ msec_to_tv (ctx->smtp_timeout_raw, &ctx->smtp_timeout);
/* Init upstreams */
if ((value = ctx->upstreams_str) != NULL) {
*/
enum process_type str_to_process (const gchar *str);
+/*
+ * Convert milliseconds to timeval fields
+ */
+#define msec_to_tv(msec, tv) do { (tv)->tv_sec = (msec) / 1000; (tv)->tv_usec = ((msec) - (tv)->tv_sec * 1000) * 1000; } while(0)
+
#endif
# include <glib/gprintf.h>
#endif
+/* 60 seconds for worker's IO */
+#define DEFAULT_WORKER_IO_TIMEOUT 60000
+
#ifndef BUILD_STATIC
#define MODULE_INIT_FUNC "module_init"
#define MODULE_AFTER_CONNECT_FUNC "after_connect"
#define MODULE_PARSE_LINE_FUNC "parse_line"
-struct custom_filter
-{
- gchar *filename; /*< filename */
- GModule *handle; /*< returned by dlopen */
- void (*init_func) (struct config_file * cfg); /*< called at start of worker */
- void *(*before_connect) (void); /*< called when clients connects */
- gboolean (*process_line) (const gchar * line, size_t len, gchar ** output, void *user_data); /*< called when client send data line */
- void (*after_connect) (gchar ** output, gchar ** log_line, void *user_data); /*< called when client disconnects */
- void (*fin_func) (void);
+struct custom_filter {
+ gchar *filename; /*< filename */
+ GModule *handle; /*< returned by dlopen */
+ void (*init_func) (struct config_file * cfg); /*< called at start of worker */
+ void *(*before_connect) (void); /*< called when clients connects */
+ gboolean (*process_line) (const gchar * line, size_t len, gchar ** output, void *user_data); /*< called when client send data line */
+ void (*after_connect) (gchar ** output, gchar ** log_line, void *user_data); /*< called when client disconnects */
+ void (*fin_func) (void);
};
#endif
/*
* Worker's context
*/
-struct rspamd_worker_ctx
-{
- struct timeval io_tv;
- /* Detect whether this worker is mime worker */
- gboolean is_mime;
- /* Detect whether this worker is mime worker */
- gboolean is_custom;
- GList *custom_filters;
- /* DNS resolver */
- struct rspamd_dns_resolver *resolver;
+struct rspamd_worker_ctx {
+ guint32 timeout;
+ struct timeval io_tv;
+ /* Detect whether this worker is mime worker */
+ gboolean is_mime;
+ /* Detect whether this worker is mime worker */
+ gboolean is_custom;
+ GList *custom_filters;
+ /* DNS resolver */
+ struct rspamd_dns_resolver *resolver;
};
static gboolean write_socket (void *arg);
new_task->is_mime = ctx->is_mime;
worker->srv->stat->connections_count++;
new_task->resolver = ctx->resolver;
- ctx->io_tv.tv_sec = WORKER_IO_TIMEOUT;
- ctx->io_tv.tv_usec = 0;
+ msec_to_tv (ctx->timeout, &ctx->io_tv);
/* Set up dispatcher */
new_task->dispatcher =
ctx = g_malloc0 (sizeof (struct rspamd_worker_ctx));
ctx->is_mime = TRUE;
+ ctx->timeout = DEFAULT_WORKER_IO_TIMEOUT;
+
register_worker_opt (TYPE_WORKER, "mime", xml_handle_boolean, ctx, G_STRUCT_OFFSET (struct rspamd_worker_ctx, is_mime));
+ register_worker_opt (TYPE_WORKER, "timeout", xml_handle_seconds, ctx, G_STRUCT_OFFSET (struct rspamd_worker_ctx, timeout));
return ctx;
}