Fix error spam in event loop when no connections are open.

On Win32 at least, select() will immediately fail with an error if
there are no file descriptors to wait for (max == 0). In the simple case
of a single XMPP session and an event loop that runs only while the
connection is open, this isn't a problem, but doesn't work for more
complex scenarios.

Add some handling so that if xmpp_run_once is called and there are no
active connections, simply sleep for duration of the timeout and
return.
This commit is contained in:
Codewalker
2014-12-24 12:08:05 -06:00
parent b753e6cf18
commit f62d817c71

View File

@@ -37,11 +37,14 @@
#ifndef _WIN32
#include <sys/select.h>
#include <errno.h>
#include <unistd.h>
#define _sleep(x) usleep(x*1000)
#else
#include <winsock2.h>
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNRESET WSAECONNRESET
#define ECONNABORTED WSAECONNABORTED
#define _sleep(x) Sleep(x)
#endif
#include <strophe.h>
@@ -225,7 +228,13 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
}
/* check for events */
ret = select(max + 1, &rfds, &wfds, NULL, &tv);
if (max > 0)
ret = select(max + 1, &rfds, &wfds, NULL, &tv);
else {
if (timeout > 0)
_sleep(timeout);
return;
}
/* select errored */
if (ret < 0) {