WvStreams
wvtimeoutex.cc
1 /*
2  * A WvTimeOut example.
3  *
4  * Should only fire once.
5  */
6 
7 #include "wvtimeoutstream.h"
8 #include "wvlog.h"
9 #include <sys/time.h>
10 
11 WvLog log("timeout", WvLog::Info);
12 
13 void timeout(WvStream &s, void *userdata)
14 {
15  static int count = 0;
16  count++;
17  log("Fire %s\n", count);
18 }
19 
20 int main()
21 {
22  WvTimeoutStream t(1000);
23  t.setcallback(timeout, NULL);
24 
25  for (int i = 0; i < 3 && t.isok(); i++)
26  {
27  if (t.select(-1))
28  t.callback();
29  }
30 
31  return 0;
32 }