--- libaitsched/example/test.c 2011/08/12 23:06:55 1.1 +++ libaitsched/example/test.c 2011/10/04 12:34:33 1.2 @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +intptr_t Kill; + +void *event(sched_task_t *arg) +{ + printf("Event::\n"); + return NULL; +} + +void *eventlo(sched_task_t *arg) +{ + printf("EventLOW::\n"); + return NULL; +} + +void *timer(sched_task_t *arg) +{ + printf("Timer 10sec::\n"); + return NULL; +} + +void *r(sched_task_t *arg) +{ + printf("read::\n"); + Kill++; + return NULL; +} + +void *w(sched_task_t *arg) +{ + printf("write::\n"); + return NULL; +} + +void *once(sched_task_t *arg) +{ + printf("once::\n"); + return NULL; +} + +int +main(int argc, char **argv) +{ + sched_root_task_t *root; + int f; + struct sockaddr_in sin; + + f = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (f == -1) + return 1; + sin.sin_len = sizeof sin; + sin.sin_family = AF_INET; + sin.sin_port = htons(2345); + sin.sin_addr.s_addr = INADDR_ANY; + if (bind(f, (struct sockaddr*) &sin, sizeof sin) == -1) + return 1; + + root = schedBegin(); + if (!root) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 1; + } + + if (!schedEvent(root, event, "piuk", 1234)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 2; + } + + if (!schedEventLo(root, eventlo, "piuk", 1111)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 3; + } + + if (!schedTimer(root, timer, "blah", 10000000)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 4; + } + + if (!schedRead(root, r, "rrr", f)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 5; + } + + if (!schedWrite(root, w, "www", f)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 6; + } + + schedCallOnce(root, once, "000000", 42); + + schedRun(root, &Kill); + schedEnd(&root); + + close(f); + return 0; +}