-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.c
More file actions
91 lines (78 loc) · 1.59 KB
/
test.c
File metadata and controls
91 lines (78 loc) · 1.59 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <fcntl.h>
#include "ringbuffer.h"
int main(int argc, const char *argv[])
{
struct ringbuffer *rb = rbuf_create(1);
if (rb == 0)
{
perror("rb_create");
return -1;
}
char *s = "0123456789ABCDEFuiocapewebvmzalwqwui";
size_t len = strlen(s);
char buf[234];
size_t nret = 0;
int count = 100; //write time
bool wr = true;
srand(time(0));
int wfd = open("wfile", O_CREAT|O_WRONLY, 0644);
if (wfd < 0)
{
goto byebye;
}
int rfd = open("rfile", O_CREAT|O_WRONLY, 0644);
if (rfd < 0)
{
goto byebye;
}
for (;;)
{
while (wr)
{
if (--count <= 0)
{
wr = false;
}
size_t wlen = rand()%len;
nret = rbuf_write(rb, s, wlen);
if (nret == 0) //full
{
break;
}
else
{
write(wfd, s, nret);
}
}
int rcount = rand()%10 + 1;
if (!wr)
{
rcount = 0x7FFFFFFF;
}
while (rcount--)
{
nret = rbuf_read(rb, buf, sizeof(buf));
if (nret == 0) //empty
{
break;
}
else
{
write(rfd, buf, nret);
}
}
if (!wr)
{
break;
}
}
byebye:
rbuf_destroy(rb);
return 0;
}