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