| 1 |
/* |
| 2 |
* libmowgli: A collection of useful routines for programming. |
| 3 |
* echoserver.c: Testing of the I/O system |
| 4 |
* |
| 5 |
* Copyright (c) 2011 William Pitcock <[email protected]> |
| 6 |
* |
| 7 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 8 |
* purpose with or without fee is hereby granted, provided that the above |
| 9 |
* copyright notice and this permission notice appear in all copies. |
| 10 |
* |
| 11 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 12 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 13 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 14 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 15 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 16 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 17 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 18 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 19 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 20 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 21 |
* POSSIBILITY OF SUCH DAMAGE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include <mowgli.h> |
| 25 |
|
| 26 |
mowgli_eventloop_t *eventloop; |
| 27 |
|
| 28 |
void |
| 29 |
timer_oneshot(void *unused) |
| 30 |
{ |
| 31 |
printf("oneshot timer hit\n"); |
| 32 |
} |
| 33 |
|
| 34 |
void |
| 35 |
timer_tick(void *unused) |
| 36 |
{ |
| 37 |
static int ticks = 0; |
| 38 |
|
| 39 |
printf("tick: %d\n", ++ticks); |
| 40 |
|
| 41 |
if (ticks > 20) |
| 42 |
mowgli_eventloop_break(eventloop); |
| 43 |
} |
| 44 |
|
| 45 |
int |
| 46 |
main(int argc, char *argv[]) |
| 47 |
{ |
| 48 |
eventloop = mowgli_eventloop_create(); |
| 49 |
|
| 50 |
mowgli_timer_add(eventloop, "timer_tick", timer_tick, NULL, 1); |
| 51 |
mowgli_timer_add_once(eventloop, "timer_oneshot", timer_oneshot, NULL, 5); |
| 52 |
|
| 53 |
mowgli_eventloop_run(eventloop); |
| 54 |
|
| 55 |
printf("eventloop halted\n"); |
| 56 |
|
| 57 |
mowgli_eventloop_destroy(eventloop); |
| 58 |
|
| 59 |
return EXIT_SUCCESS; |
| 60 |
} |