WvTimeoutStream is a stream that becomes !isok() after a configurable number of milliseconds. It will wake up a select(). It will return true if select()ed and that the timeout has expired. But using it in a WvStreamList will not have it call the callback/execute because the WvStreamList checks whether isok() is true before doing the select().
/*
* A WvTimeOut example.
*
* Should only fire once.
*/
#include "wvtimeoutstream.h"
#include "wvlog.h"
#include <sys/time.h>
WvLog log("timeout", WvLog::Info);
void timeout(WvStream &s, void *userdata)
{
static int count = 0;
count++;
log("Fire %s\n", count);
}
int main()
{
WvTimeoutStream t(1000);
t.setcallback(timeout, NULL);
for (int i = 0; i < 3 && t.isok(); i++)
{
if (t.select(-1))
t.callback();
}
return 0;
}