From cd2cf6eb23ffbb1bb4943906365823aa090813d6 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 5 Jul 2017 15:29:31 +0300 Subject: [PATCH] ctx: set default event loop timeout to 1 second Default timeout was 1 millisecond and it consumed CPU by running the loop in xmpp_run(). The CPU usage was unacceptable and thus xmpp_run() was not used by users. Also user can set the timeout by xmpp_ctx_set_timeout() now. Event loop already handles the situation when there is a timed handler which needs to be run before the timeout is reached. Also system awakes event loop when data arrives to socket. The only drawback is when timed handler sends data it will be actually sent after select(2) returns. But this situation can be handled easily by adding socket to wfds when xmpp_conn_t contains data in sending queue. --- src/ctx.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ctx.c b/src/ctx.c index 444ea18..cb19b29 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -91,12 +91,12 @@ void xmpp_shutdown(void) #define LIBXMPP_VERSION_MINOR (0) #endif -#ifndef DEFAULT_TIMEOUT -/** @def DEFAULT_TIMEOUT +#ifndef EVENT_LOOP_DEFAULT_TIMEOUT +/** @def EVENT_LOOP_DEFAULT_TIMEOUT * The default timeout in milliseconds for the event loop. - * This is set to 1 millisecond. + * This is set to 1 second. */ -#define DEFAULT_TIMEOUT 1 +#define EVENT_LOOP_DEFAULT_TIMEOUT 1000 #endif /** Check that Strophe supports a specific API version. @@ -417,7 +417,7 @@ xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem, ctx->connlist = NULL; ctx->loop_status = XMPP_LOOP_NOTSTARTED; ctx->rand = xmpp_rand_new(ctx); - ctx->timeout = DEFAULT_TIMEOUT; + ctx->timeout = EVENT_LOOP_DEFAULT_TIMEOUT; if (ctx->rand == NULL) { xmpp_free(ctx, ctx); ctx = NULL;