1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <string.h>
4: #include <unistd.h>
5: #include <fcntl.h>
6: #include <signal.h>
7: #include <sys/types.h>
8: #include <sys/stat.h>
9: #include <sys/socket.h>
10: #include <netinet/in.h>
11: #include <aitsched.h>
12:
13: intptr_t Kill;
14:
15: void *event(sched_task_t *arg)
16: {
17: printf("Event::\n");
18: return NULL;
19: }
20:
21: void *eventlo(sched_task_t *arg)
22: {
23: printf("EventLOW::\n");
24: return NULL;
25: }
26:
27: void *timer(sched_task_t *arg)
28: {
29: printf("Timer %p sec::\n", TASK_ARG(arg));
30: return NULL;
31: }
32:
33: void *r(sched_task_t *arg)
34: {
35: printf("read:: bytes\n");
36: Kill++;
37: return NULL;
38: }
39:
40: void *w(sched_task_t *arg)
41: {
42: printf("write::\n");
43: return NULL;
44: }
45:
46: void *once(sched_task_t *arg)
47: {
48: printf("once::\n");
49: return NULL;
50: }
51:
52: void *aiowrite(sched_task_t *arg)
53: {
54: printf("AIO write[%d]:: %d bytes\n", TASK_FD(arg), (int) TASK_DATLEN(arg));
55: free(TASK_DATA(arg));
56: return NULL;
57: }
58:
59: void *aioread(sched_task_t *arg)
60: {
61: char *ole = malloc(BUFSIZ);
62:
63: printf("AIO read[%d]:: %d bytes\n", TASK_FD(arg), (int) TASK_DATLEN(arg));
64:
65: write((int) TASK_ARG(arg), TASK_DATA(arg), TASK_DATLEN(arg));
66: free(TASK_DATA(arg));
67:
68: schedAIOWrite(TASK_ROOT(arg), aiowrite, TASK_ARG(arg), TASK_FD(arg), ole,
69: strlcpy(ole, "BAHURA OR CULTURE .... A CULTURE OR BAHURA :-)\n", BUFSIZ));
70: return NULL;
71: }
72:
73: void sig(int s)
74: {
75: switch (s) {
76: case SIGTERM:
77: Kill++;
78: break;
79: }
80: }
81:
82: int
83: main(int argc, char **argv)
84: {
85: sched_root_task_t *root;
86: int f, fd;
87: struct sockaddr_in sin;
88: struct timespec ts = { 20, 0 };
89: // struct timespec p = { 0, 10000000 };
90: struct sigaction sa;
91: char *ole = malloc(BUFSIZ);
92:
93: sa.sa_handler = sig;
94: sigemptyset(&sa.sa_mask);
95: sigaction(SIGTERM, &sa, NULL);
96:
97: f = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
98: if (f == -1)
99: return 1;
100: sin.sin_len = sizeof sin;
101: sin.sin_family = AF_INET;
102: sin.sin_port = htons(2345);
103: sin.sin_addr.s_addr = INADDR_ANY;
104: if (bind(f, (struct sockaddr*) &sin, sizeof sin) == -1)
105: return 1;
106:
107: fd = open("test_aio.dat", O_CREAT | O_RDWR | O_TRUNC, 0644);
108: if (fd == -1)
109: return 1;
110:
111: root = schedBegin();
112: if (!root) {
113: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
114: return 1;
115: }
116:
117: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
118: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
119: return 4;
120: } else
121: ts.tv_sec = 15;
122: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
123: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
124: return 4;
125: } else
126: ts.tv_sec = 10;
127:
128: if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
129: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
130: return 2;
131: }
132:
133: if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
134: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
135: return 3;
136: }
137:
138: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
139: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
140: return 4;
141: }
142:
143: if (!schedRead(root, r, "rrr", f, NULL, 0)) {
144: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
145: return 5;
146: }
147:
148: if (!schedWrite(root, w, "www", f, NULL, 0)) {
149: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
150: return 6;
151: }
152:
153: if (!schedAIORead(root, aioread, (void*) f, fd, ole, BUFSIZ))
154: printf("Warning:: #%d - %s\n", sched_GetErrno(), sched_GetError());
155:
156: schedCallOnce(root, once, "000000", 42, NULL, 0);
157:
158: // schedPolling(root, &p, NULL);
159: schedRun(root, &Kill);
160: schedEnd(&root);
161:
162: close(fd);
163: close(f);
164: return 0;
165: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>