Annotation of libaitsched/example/test.c, revision 1.2
1.2 ! misho 1: #include <stdio.h>
! 2: #include <unistd.h>
! 3: #include <fcntl.h>
! 4: #include <sys/types.h>
! 5: #include <sys/stat.h>
! 6: #include <sys/socket.h>
! 7: #include <netinet/in.h>
! 8: #include <aitsched.h>
! 9:
! 10: intptr_t Kill;
! 11:
! 12: void *event(sched_task_t *arg)
! 13: {
! 14: printf("Event::\n");
! 15: return NULL;
! 16: }
! 17:
! 18: void *eventlo(sched_task_t *arg)
! 19: {
! 20: printf("EventLOW::\n");
! 21: return NULL;
! 22: }
! 23:
! 24: void *timer(sched_task_t *arg)
! 25: {
! 26: printf("Timer 10sec::\n");
! 27: return NULL;
! 28: }
! 29:
! 30: void *r(sched_task_t *arg)
! 31: {
! 32: printf("read::\n");
! 33: Kill++;
! 34: return NULL;
! 35: }
! 36:
! 37: void *w(sched_task_t *arg)
! 38: {
! 39: printf("write::\n");
! 40: return NULL;
! 41: }
! 42:
! 43: void *once(sched_task_t *arg)
! 44: {
! 45: printf("once::\n");
! 46: return NULL;
! 47: }
! 48:
! 49: int
! 50: main(int argc, char **argv)
! 51: {
! 52: sched_root_task_t *root;
! 53: int f;
! 54: struct sockaddr_in sin;
! 55:
! 56: f = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
! 57: if (f == -1)
! 58: return 1;
! 59: sin.sin_len = sizeof sin;
! 60: sin.sin_family = AF_INET;
! 61: sin.sin_port = htons(2345);
! 62: sin.sin_addr.s_addr = INADDR_ANY;
! 63: if (bind(f, (struct sockaddr*) &sin, sizeof sin) == -1)
! 64: return 1;
! 65:
! 66: root = schedBegin();
! 67: if (!root) {
! 68: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 69: return 1;
! 70: }
! 71:
! 72: if (!schedEvent(root, event, "piuk", 1234)) {
! 73: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 74: return 2;
! 75: }
! 76:
! 77: if (!schedEventLo(root, eventlo, "piuk", 1111)) {
! 78: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 79: return 3;
! 80: }
! 81:
! 82: if (!schedTimer(root, timer, "blah", 10000000)) {
! 83: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 84: return 4;
! 85: }
! 86:
! 87: if (!schedRead(root, r, "rrr", f)) {
! 88: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 89: return 5;
! 90: }
! 91:
! 92: if (!schedWrite(root, w, "www", f)) {
! 93: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 94: return 6;
! 95: }
! 96:
! 97: schedCallOnce(root, once, "000000", 42);
! 98:
! 99: schedRun(root, &Kill);
! 100: schedEnd(&root);
! 101:
! 102: close(f);
! 103: return 0;
! 104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>