diff --git a/src/common.h b/src/common.h index 184b97a..2f1d8c6 100644 --- a/src/common.h +++ b/src/common.h @@ -50,6 +50,8 @@ struct _xmpp_ctx_t { xmpp_rand_t *rand; xmpp_loop_status_t loop_status; xmpp_connlist_t *connlist; + + unsigned long timeout; }; diff --git a/src/ctx.c b/src/ctx.c index e57ed47..9885154 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -91,6 +91,14 @@ void xmpp_shutdown(void) #define LIBXMPP_VERSION_MINOR (0) #endif +#ifndef DEFAULT_TIMEOUT +/** @def DEFAULT_TIMEOUT + * The default timeout in milliseconds for the event loop. + * This is set to 1 millisecond. + */ +#define DEFAULT_TIMEOUT 1 +#endif + /** Check that Strophe supports a specific API version. * * @param major the major version number @@ -410,6 +418,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; if (ctx->rand == NULL) { xmpp_free(ctx, ctx); ctx = NULL; @@ -432,3 +441,15 @@ void xmpp_ctx_free(xmpp_ctx_t * const ctx) xmpp_free(ctx, ctx); /* pull the hole in after us */ } +/** Set the timeout to use when calling xmpp_run(). + * + * @param ctx a Strophe context object + * @param timeout the time to wait for events in milliseconds + * + * @ingroup Context + */ +void xmpp_ctx_set_timeout(xmpp_ctx_t * const ctx, const unsigned long timeout) +{ + ctx->timeout = timeout; +} + diff --git a/src/event.c b/src/event.c index b722e6c..c7fd886 100644 --- a/src/event.c +++ b/src/event.c @@ -51,14 +51,6 @@ #include "common.h" #include "parser.h" -#ifndef DEFAULT_TIMEOUT -/** @def DEFAULT_TIMEOUT - * The default timeout in milliseconds for the event loop. - * This is set to 1 millisecond. - */ -#define DEFAULT_TIMEOUT 1 -#endif - /** Run the event loop once. * This function will run send any data that has been queued by * xmpp_send and related functions and run through the Strophe even @@ -333,7 +325,7 @@ void xmpp_run(xmpp_ctx_t *ctx) ctx->loop_status = XMPP_LOOP_RUNNING; while (ctx->loop_status == XMPP_LOOP_RUNNING) { - xmpp_run_once(ctx, DEFAULT_TIMEOUT); + xmpp_run_once(ctx, ctx->timeout); } /* make it possible to start event loop again */ diff --git a/strophe.h b/strophe.h index 8e474b1..2f78629 100644 --- a/strophe.h +++ b/strophe.h @@ -117,6 +117,7 @@ typedef struct _xmpp_ctx_t xmpp_ctx_t; xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem, const xmpp_log_t * const log); void xmpp_ctx_free(xmpp_ctx_t * const ctx); +void xmpp_ctx_set_timeout(xmpp_ctx_t * const ctx, const unsigned long timeout); /* free some blocks returned by other APIs, for example the buffer you get from xmpp_stanza_to_text */