Event loop

These functions manage the Strophe event loop. More...

## Functions

void | xmpp_run_once (xmpp_ctx_t *ctx, unsigned long timeout)
| Run the event loop once.
void | xmpp_run (xmpp_ctx_t *ctx)
| Start the event loop.
void | xmpp_stop (xmpp_ctx_t *ctx)
| Stop the event loop.
void | xmpp_ctx_set_timeout (xmpp_ctx_t *ctx, unsigned long timeout)
| Set the timeout to use when calling xmpp_run().

## Detailed Description

These functions manage the Strophe event loop.

Simple tools can use xmpp_run() and xmpp_stop() to manage the life cycle of the program. A common idiom is to set up a few initial event handers, call xmpp_run(), and then respond and react to events as they come in. At some point, one of the handlers will call xmpp_stop() to quit the event loop which leads to the program terminating.

More complex programs will have their own event loops, and should ensure that xmpp_run_once() is called regularly from there. For example, a GUI program will already include an event loop to process UI events from users, and xmpp_run_once() would be called from an idle function.

## Function Documentation

## xmpp_run_once()

void xmpp_run_once | ( | xmpp_ctx_t * | ctx,
|  | unsigned long | timeout
| ) |  |

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 loop a single time, and will not wait more than timeout milliseconds for events. This is provided to support integration with event loops outside the library, and if used, should be called regularly to achieve low latency event handling.

Parameters

  ctx | a Strophe context object
  timeout | time to wait for events in milliseconds

## xmpp_run()

void xmpp_run | ( | xmpp_ctx_t * | ctx | ) |

Start the event loop.

This function continuously calls xmpp_run_once and does not return until xmpp_stop has been called.

Parameters

  ctx | a Strophe context object

## xmpp_stop()

void xmpp_stop | ( | xmpp_ctx_t * | ctx | ) |

Stop the event loop.

This will stop the event loop after the current iteration and cause xmpp_run to exit.

Parameters

  ctx | a Strophe context object

## xmpp_ctx_set_timeout()

void xmpp_ctx_set_timeout | ( | xmpp_ctx_t * | ctx,
|  | unsigned long | timeout
| ) |  |

Set the timeout to use when calling xmpp_run().

Parameters

  ctx | a Strophe context object
  timeout | the time to wait for events in milliseconds