This program is a good example to start with. It only uses one time-based event. Before entering the main loop, the event is scheduled to happen 5 seconds later since the moment of calling SetFromNow(), then the event is registered with the selector and the main loop is launched. Once the event came, it is handled by the function AbortingTimeout::TimeoutHandle() which causes the main loop to exit using the SUEEventSelector::Break() method. All the example program do is sleeping for 5 seconds and then exiting.
/* This simple demo program just sleeps 5 seconds and exits using SUE mechanism of timeout events */ #include <stdio.h> #include "sue_sel.hpp" class AbortingTimeout : public SUETimeoutHandler { SUEEventSelector *selector; public: AbortingTimeout(SUEEventSelector *a_sel) { selector = a_sel; } ~AbortingTimeout() {} virtual void TimeoutHandle() { selector->Break(); } }; int main() { SUEEventSelector selector; AbortingTimeout atm(&selector); atm.SetFromNow(5); // 5 seconds selector.RegisterTimeoutHandler(&atm); printf("Entering the main loop... \n"); selector.Go(); printf("Main loop exited\n"); return 0; }