Annotation of libaitsched/example/test.c, revision 1.4.4.1
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: {
1.4.4.1 ! misho 26: printf("Timer %ld sec::\n", (intptr_t) TASK_ARG(arg));
1.2 misho 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;
1.4.4.1 ! misho 55: struct timespec ts = { 20, 0 };
! 56: struct timespec p = { 0, 10000000 };
1.2 misho 57:
58: f = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
59: if (f == -1)
60: return 1;
61: sin.sin_len = sizeof sin;
62: sin.sin_family = AF_INET;
63: sin.sin_port = htons(2345);
64: sin.sin_addr.s_addr = INADDR_ANY;
65: if (bind(f, (struct sockaddr*) &sin, sizeof sin) == -1)
66: return 1;
67:
68: root = schedBegin();
69: if (!root) {
70: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
71: return 1;
72: }
73:
1.4.4.1 ! misho 74: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
! 75: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 76: return 4;
! 77: } else
! 78: ts.tv_sec = 15;
! 79: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
! 80: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
! 81: return 4;
! 82: } else
! 83: ts.tv_sec = 10;
! 84:
1.4 misho 85: if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
1.2 misho 86: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
87: return 2;
88: }
89:
1.4 misho 90: if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
1.2 misho 91: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
92: return 3;
93: }
94:
1.4.4.1 ! misho 95: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
1.2 misho 96: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
97: return 4;
98: }
99:
1.4 misho 100: if (!schedRead(root, r, "rrr", f, NULL, 0)) {
1.2 misho 101: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
102: return 5;
103: }
104:
1.4 misho 105: if (!schedWrite(root, w, "www", f, NULL, 0)) {
1.2 misho 106: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
107: return 6;
108: }
109:
1.4 misho 110: schedCallOnce(root, once, "000000", 42, NULL, 0);
1.2 misho 111:
1.4.4.1 ! misho 112: schedPolling(root, &p, NULL);
1.2 misho 113: schedRun(root, &Kill);
114: schedEnd(&root);
115:
116: close(f);
117: return 0;
118: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>