Annotation of libaitsched/example/test.c, revision 1.1.2.5
1.1.2.1 misho 1: #include <stdio.h>
1.1.2.2 misho 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>
1.1.2.1 misho 8: #include <aitsched.h>
9:
1.1.2.5 ! misho 10: intptr_t Kill;
! 11:
1.1.2.4 misho 12: void *event(sched_task_t *arg)
1.1.2.1 misho 13: {
1.1.2.2 misho 14: printf("Event::\n");
15: return NULL;
16: }
17:
1.1.2.4 misho 18: void *eventlo(sched_task_t *arg)
1.1.2.2 misho 19: {
20: printf("EventLOW::\n");
21: return NULL;
22: }
23:
1.1.2.4 misho 24: void *timer(sched_task_t *arg)
1.1.2.2 misho 25: {
26: printf("Timer 10sec::\n");
27: return NULL;
28: }
29:
1.1.2.4 misho 30: void *r(sched_task_t *arg)
1.1.2.2 misho 31: {
32: printf("read::\n");
1.1.2.5 ! misho 33: Kill++;
1.1.2.2 misho 34: return NULL;
35: }
36:
1.1.2.4 misho 37: void *w(sched_task_t *arg)
1.1.2.2 misho 38: {
39: printf("write::\n");
40: return NULL;
41: }
42:
1.1.2.4 misho 43: void *once(sched_task_t *arg)
1.1.2.2 misho 44: {
45: printf("once::\n");
1.1.2.1 misho 46: return NULL;
47: }
48:
49: int
50: main(int argc, char **argv)
51: {
52: sched_root_task_t *root;
1.1.2.2 misho 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;
1.1.2.1 misho 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:
1.1.2.2 misho 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:
1.1.2.5 ! misho 99: schedRun(root, &Kill);
1.1.2.3 misho 100: schedEnd(&root);
1.1.2.2 misho 101:
102: close(f);
1.1.2.1 misho 103: return 0;
104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>