forked from cloudwu/mread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
38 lines (35 loc) · 608 Bytes
/
main.c
File metadata and controls
38 lines (35 loc) · 608 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "mread.h"
#include <stdio.h>
#include <unistd.h>
static void
test(struct mread_pool *m) {
int id = mread_poll(m,0);
if (id >= 0) {
for (;;) {
char * buffer = mread_pull(m, 4);
if (buffer == NULL) {
if (mread_closed(m)) {
printf("%d: CLOSED\n",id);
}
break;
} else {
printf("%d : %d %d %d %d\n",id, buffer[0],buffer[1],buffer[2],buffer[3]);
mread_yield(m);
}
}
}
}
int
main() {
struct mread_pool * m = mread_create(2525 , 10, 0);
if (m == NULL) {
perror("error:");
return 1;
}
for (;;) {
test(m);
sleep(1);
}
mread_close(m);
return 0;
}