-
Notifications
You must be signed in to change notification settings - Fork 1
/
client-timer.c
executable file
·118 lines (101 loc) · 2.87 KB
/
client-timer.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/******************************************************************************
*
* FILE NAME : client-timer.c
* VERSION : 1.0
* DESCRIPTION: program for testing posix timer...
*
******************************************************************************/
#include <unistd.h>
#include "client-timer.h"
#include "timeout-handler.h"
/******************************************************************************
* FUNCTION : clientClientInit()
* DESCRIPTION : init environment for running
* INPUT :
* OUTPUT :
* RETURN : 0:success; -1:failed
******************************************************************************/
int clientClientInit(void)
{
int iRet = CLIENT_ERR;
/* init timer, used to handle timeout event */
iRet = initClientTimer();
if (CLIENT_OK != iRet)
{
MSG_ERR("init client-client's timer failed!\n");
(void)clientDeleteAllTimer();
return CLIENT_ERR;
}
MSG_LOG("Init client-client environment successful.\n");
return CLIENT_OK;
}
/******************************************************************************
* FUNCTION : clientClientExit()
* DESCRIPTION : clean source befor exit client client
* INPUT :
* OUTPUT :
* RETURN : 0:success; -1:failed
******************************************************************************/
int clientClientExit(void)
{
int iRet = CLIENT_ERR;
iRet = clientDeleteAllTimer();
if (CLIENT_OK != iRet)
{
MSG_ERR("fatal error: delete timer failed.\n");
return CLIENT_ERR;
}
return CLIENT_OK;
}
/******************************************************************************
* FUNCTION : posixTimerTest()
* DESCRIPTION : test posix timer
* INPUT :
* OUTPUT :
* RETURN :
******************************************************************************/
static void posixTimerTest()
{
int i = 0;
OPEAR_ARR operas[OPERA_NUM] = {0};
MSG_LOG("please input %d operations: \n", OPERA_NUM);
for (i = 0; i < OPERA_NUM; i++)
{
printf("No%d:\n", i);
scanf("%d %d", &(operas[i].opera), &(operas[i].timer));
}
for (i = 0; i < OPERA_NUM; i++)
{
(void)clientTimerSwitch(operas[i].timer, operas[i].opera);
sleep(SLEEP_TIME);
}
return ;
}
/******************************************************************************
* FUNCTION : main()
* DESCRIPTION :
* INPUT :
* OUTPUT :
* RETURN :
******************************************************************************/
int main(int argc, char** argv)
{
int iRet = CLIENT_ERR;
/* init posix timer */
iRet = clientClientInit();
if (CLIENT_OK != iRet)
{
MSG_ERR("init client client environment failed!\n");
return CLIENT_ERR;
}
/* test posix timer */
posixTimerTest();
/* release timers before exit */
iRet = clientClientExit();
if (CLIENT_OK != iRet)
{
MSG_ERR("clientClientExit failed!\n");
return CLIENT_ERR;
}
return CLIENT_OK;
}