32
32
**
33
33
*/
34
34
35
-
36
35
#include "igmpproxy.h"
37
36
38
37
/* the code below implements a callout queue */
39
- static int id = 0 ;
40
- static struct timeOutQueue * queue = 0 ; /* pointer to the beginning of timeout queue */
38
+ static int id = 0 ;
39
+ static struct timeOutQueue * queue = 0 ; /* pointer to the beginning of timeout queue */
41
40
42
41
struct timeOutQueue {
43
- struct timeOutQueue * next ; // Next event in queue
44
- int id ;
45
- timer_f func ; // function to call
46
- void * data ; // Data for function
47
- int time ; // Time offset for next event
42
+ struct timeOutQueue * next ; // Next event in queue
43
+ int id ;
44
+ timer_f func ; // function to call
45
+ void * data ; // Data for function
46
+ int time ; // Time offset for next event
48
47
};
49
48
50
49
// Method for dumping the Queue to the log.
@@ -53,44 +52,47 @@ static void debugQueue(void);
53
52
/**
54
53
* Initializes the callout queue
55
54
*/
56
- void callout_init (void ) {
55
+ void callout_init (void )
56
+ {
57
57
queue = NULL ;
58
58
}
59
59
60
60
/**
61
61
* Clears all scheduled timeouts...
62
62
*/
63
- void free_all_callouts (void ) {
63
+ void free_all_callouts (void )
64
+ {
64
65
struct timeOutQueue * p ;
65
66
66
67
while (queue ) {
67
- p = queue ;
68
+ p = queue ;
68
69
queue = queue -> next ;
69
70
free (p );
70
71
}
71
72
}
72
73
73
-
74
74
/**
75
75
* elapsed_time seconds have passed; perform all the events that should
76
76
* happen.
77
77
*/
78
- void age_callout_queue (int elapsed_time ) {
78
+ void age_callout_queue (int elapsed_time )
79
+ {
79
80
struct timeOutQueue * ptr ;
80
81
struct timeOutQueue * _queue = NULL ;
81
- struct timeOutQueue * last = NULL ;
82
- int i = 0 ;
82
+ struct timeOutQueue * last = NULL ;
83
+ int i = 0 ;
83
84
84
85
for (ptr = queue ; ptr ; ptr = ptr -> next ) {
85
86
if (ptr -> time > elapsed_time ) {
86
87
ptr -> time -= elapsed_time ;
87
88
break ;
88
- } else {
89
+ }
90
+ else {
89
91
elapsed_time -= ptr -> time ;
90
92
if (_queue == NULL )
91
93
_queue = ptr ;
92
- last = ptr ;
93
- }
94
+ last = ptr ;
95
+ }
94
96
}
95
97
96
98
queue = ptr ;
@@ -103,7 +105,7 @@ void age_callout_queue(int elapsed_time) {
103
105
_queue = _queue -> next ;
104
106
my_log (LOG_DEBUG , 0 , "About to call timeout %d (#%d)" , ptr -> id , i );
105
107
if (ptr -> func )
106
- ptr -> func (ptr -> data );
108
+ ptr -> func (ptr -> data );
107
109
free (ptr );
108
110
}
109
111
}
@@ -112,11 +114,11 @@ void age_callout_queue(int elapsed_time) {
112
114
* Return in how many seconds age_callout_queue() would like to be called.
113
115
* Return -1 if there are no events pending.
114
116
*/
115
- int timer_nextTimer (void ) {
117
+ int timer_nextTimer (void )
118
+ {
116
119
if (queue ) {
117
120
if (queue -> time < 0 ) {
118
- my_log (LOG_WARNING , 0 , "timer_nextTimer top of queue says %d" ,
119
- queue -> time );
121
+ my_log (LOG_WARNING , 0 , "timer_nextTimer top of queue says %d" , queue -> time );
120
122
return 0 ;
121
123
}
122
124
return queue -> time ;
@@ -130,12 +132,13 @@ int timer_nextTimer(void) {
130
132
* @param action - The function to call on timeout.
131
133
* @param data - Pointer to the function data to supply...
132
134
*/
133
- int timer_setTimer (int delay , timer_f action , void * data ) {
134
- struct timeOutQueue * ptr , * node , * prev ;
135
- int i = 0 ;
135
+ int timer_setTimer (int delay , timer_f action , void * data )
136
+ {
137
+ struct timeOutQueue * ptr , * node , * prev ;
138
+ int i = 0 ;
136
139
137
140
/* create a node */
138
- node = (struct timeOutQueue * )malloc (sizeof (struct timeOutQueue ));
141
+ node = (struct timeOutQueue * ) malloc (sizeof (struct timeOutQueue ));
139
142
if (node == 0 ) {
140
143
my_log (LOG_WARNING , 0 , "Malloc Failed in timer_settimer\n" );
141
144
return -1 ;
@@ -167,23 +170,22 @@ int timer_setTimer(int delay, timer_f action, void *data) {
167
170
prev -> next = node ;
168
171
}
169
172
ptr -> time -= node -> time ;
170
- my_log (LOG_DEBUG , 0 ,
171
- "Created timeout %d (#%d) - delay %d secs" ,
172
- node -> id , i , node -> time );
173
+ my_log (LOG_DEBUG , 0 , "Created timeout %d (#%d) - delay %d secs" , node -> id , i , node -> time );
173
174
debugQueue ();
174
175
return node -> id ;
175
- } else {
176
+ }
177
+ else {
176
178
// Continur to check nodes.
177
- delay -= ptr -> time ; node -> time = delay ;
178
- prev = ptr ;
179
- ptr = ptr -> next ;
179
+ delay -= ptr -> time ;
180
+ node -> time = delay ;
181
+ prev = ptr ;
182
+ ptr = ptr -> next ;
180
183
}
181
184
i ++ ;
182
185
}
183
186
prev -> next = node ;
184
187
}
185
- my_log (LOG_DEBUG , 0 , "Created timeout %d (#%d) - delay %d secs" ,
186
- node -> id , i , node -> time );
188
+ my_log (LOG_DEBUG , 0 , "Created timeout %d (#%d) - delay %d secs" , node -> id , i , node -> time );
187
189
debugQueue ();
188
190
189
191
return node -> id ;
@@ -192,9 +194,10 @@ int timer_setTimer(int delay, timer_f action, void *data) {
192
194
/**
193
195
* returns the time until the timer is scheduled
194
196
*/
195
- int timer_leftTimer (int timer_id ) {
197
+ int timer_leftTimer (int timer_id )
198
+ {
196
199
struct timeOutQueue * ptr ;
197
- int left = 0 ;
200
+ int left = 0 ;
198
201
199
202
if (!timer_id )
200
203
return -1 ;
@@ -211,9 +214,10 @@ int timer_leftTimer(int timer_id) {
211
214
/**
212
215
* clears the associated timer. Returns 1 if succeeded.
213
216
*/
214
- int timer_clearTimer (int timer_id ) {
215
- struct timeOutQueue * ptr , * prev ;
216
- int i = 0 ;
217
+ int timer_clearTimer (int timer_id )
218
+ {
219
+ struct timeOutQueue * ptr , * prev ;
220
+ int i = 0 ;
217
221
218
222
if (!timer_id )
219
223
return 0 ;
@@ -248,7 +252,7 @@ int timer_clearTimer(int timer_id) {
248
252
return 1 ;
249
253
}
250
254
prev = ptr ;
251
- ptr = ptr -> next ;
255
+ ptr = ptr -> next ;
252
256
i ++ ;
253
257
}
254
258
// If we get here, the timer was not deleted.
@@ -260,8 +264,9 @@ int timer_clearTimer(int timer_id) {
260
264
/**
261
265
* debugging utility
262
266
*/
263
- static void debugQueue (void ) {
264
- struct timeOutQueue * ptr ;
267
+ static void debugQueue (void )
268
+ {
269
+ struct timeOutQueue * ptr ;
265
270
266
271
for (ptr = queue ; ptr ; ptr = ptr -> next ) {
267
272
my_log (LOG_DEBUG , 0 , "(Id:%d, Time:%d) " , ptr -> id , ptr -> time );
0 commit comments