Programmer's Guide to the WvStreams Libraries | ||
---|---|---|
Prev | Chapter 10. WvStream - communications fundamentals | Next |
We should mention that you can use the select() function for millisecond-resolution delays, or to timeout when no data is received for a certain amount of time. The following example babbles something at you after every second of no input, and exits if you don't say anything for ten seconds.
/* * A WvStream example. * * Some text about this example... */ #include <wvstream.h> int main() { int nothing_count = 0; wvcon->autoforward(*wvcon); while (wvcon->isok()) { if (wvcon->select(1000)) { nothing_count = 0; wvcon->callback(); } else { nothing_count++; wvcon->print("[TICK]"); if (nothing_count == 10) { wvcon->print("[TIMEOUT]\n"); break; } } } }