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.
This commit is contained in:
10
src/ctx.c
10
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;
|
||||
|
||||
Reference in New Issue
Block a user