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 *aioread(sched_task_t *arg);
53: void *aiowrite(sched_task_t *arg)
54: {
55: char *ole = malloc(BUFSIZ);
56:
57: printf("AIO write[%d]:: %d bytes\n", TASK_FD(arg), (int) TASK_DATLEN(arg));
58: free(TASK_DATA(arg));
59:
60: schedAIORead(TASK_ROOT(arg), aioread, NULL, TASK_FD(arg), ole, BUFSIZ);
61: return NULL;
62: }
63:
64: void *aioread(sched_task_t *arg)
65: {
66: char *ole = malloc(BUFSIZ);
67:
68: printf("AIO read[%d]:: %d bytes\n%s\n-------\n", TASK_FD(arg), (int) TASK_DATLEN(arg),
69: (char*) TASK_DATA(arg));
70:
71: if (TASK_ARG(arg)) {
72: write((int) TASK_ARG(arg), TASK_DATA(arg), TASK_DATLEN(arg));
73:
74: schedAIOWrite(TASK_ROOT(arg), aiowrite, TASK_ARG(arg), TASK_FD(arg), ole,
75: strlcpy(ole, "++++++BAHURA OR CULTURE .... A CULTURE OR BAHURA :-)\n", BUFSIZ));
76: }
77: free(TASK_DATA(arg));
78: return NULL;
79: }
80:
81: void sig(int s)
82: {
83: switch (s) {
84: case SIGTERM:
85: Kill++;
86: break;
87: }
88: }
89:
90: int
91: main(int argc, char **argv)
92: {
93: sched_root_task_t *root;
94: int f, fd;
95: struct sockaddr_in sin;
96: struct timespec ts = { 20, 0 };
97: // struct timespec p = { 0, 10000000 };
98: struct sigaction sa;
99: char *ole = malloc(BUFSIZ);
100:
101: sa.sa_handler = sig;
102: sigemptyset(&sa.sa_mask);
103: sigaction(SIGTERM, &sa, NULL);
104:
105: f = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
106: if (f == -1)
107: return 1;
108: sin.sin_len = sizeof sin;
109: sin.sin_family = AF_INET;
110: sin.sin_port = htons(2345);
111: sin.sin_addr.s_addr = INADDR_ANY;
112: if (bind(f, (struct sockaddr*) &sin, sizeof sin) == -1)
113: return 1;
114:
115: fd = open("test_aio.dat", O_CREAT | O_RDWR, 0644);
116: if (fd == -1)
117: return 1;
118: printf("fd=%d\n", fd);
119:
120: root = schedBegin();
121: if (!root) {
122: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
123: return 1;
124: }
125:
126: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
127: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
128: return 4;
129: } else
130: ts.tv_sec = 15;
131: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
132: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
133: return 4;
134: } else
135: ts.tv_sec = 10;
136:
137: if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
138: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
139: return 2;
140: }
141:
142: if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
143: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
144: return 3;
145: }
146:
147: if (!schedTimer(root, timer, (void*) (intptr_t) ts.tv_sec, ts, NULL, 0)) {
148: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
149: return 4;
150: }
151:
152: if (!schedRead(root, r, "rrr", f, NULL, 0)) {
153: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
154: return 5;
155: }
156:
157: if (!schedWrite(root, w, "www", f, NULL, 0)) {
158: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
159: return 6;
160: }
161:
162: if (!schedAIORead(root, aioread, (void*) f, fd, ole, BUFSIZ))
163: printf("Warning:: #%d - %s\n", sched_GetErrno(), sched_GetError());
164:
165: schedCallOnce(root, once, "000000", 42, NULL, 0);
166:
167: // schedPolling(root, &p, NULL);
168: schedRun(root, &Kill);
169: schedEnd(&root);
170:
171: close(fd);
172: close(f);
173: return 0;
174: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>