-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathexample.c
58 lines (50 loc) · 1.05 KB
/
example.c
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
#include "timeout_wrapper.h"
int
sim_oci_call(int a, int b) {
int ret;
while(1)
ret = a + b;
return a+b;
}
int
test1()
{
int ret = 0;
int try_times = 3;
int interval = 1000;
add_timeout_to_func(sim_oci_call, try_times, interval, ret, 1, 2);
if (ret == E_CALL_TIMEOUT) {
printf("invoke sim_oci_call timeouts for 3 times\n");
return -1;
} else if (ret == 0) {
printf("invoke sim_oci_call ok\n");
return 0;
} else {
printf("timeout_func error = %d\n", ret);
}
}
int
test2()
{
#define MAXLINE 1024
char line[MAXLINE];
int ret = 0;
int try_times = 3;
int interval = 1000;
add_timeout_to_func(read, try_times, interval, ret, STDIN_FILENO, line, MAXLINE);
if (ret == E_CALL_TIMEOUT) {
printf("invoke read timeouts for 3 times\n");
return -1;
} else if (ret == 0) {
printf("invoke read ok\n");
return 0;
} else {
printf("timeout_func error = %d\n", ret);
}
}
int
main()
{
test1();
test2();
}