3232**
3333*/
3434
35-
3635#include "igmpproxy.h"
3736
3837/* 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 */
4140
4241struct 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
4847};
4948
5049// Method for dumping the Queue to the log.
51- static void debugQueue (void );
50+ static void debugQueue ( void );
5251
5352/**
5453* Initializes the callout queue
5554*/
56- void callout_init (void ) {
55+ void callout_init ( void )
56+ {
5757 queue = NULL ;
5858}
5959
6060/**
6161* Clears all scheduled timeouts...
6262*/
63- void free_all_callouts (void ) {
63+ void free_all_callouts ( void )
64+ {
6465 struct timeOutQueue * p ;
6566
66- while (queue ) {
67- p = queue ;
67+ while ( queue ) {
68+ p = queue ;
6869 queue = queue -> next ;
69- free (p );
70+ free ( p );
7071 }
7172}
7273
73-
7474/**
7575 * elapsed_time seconds have passed; perform all the events that should
7676 * happen.
7777 */
78- void age_callout_queue (int elapsed_time ) {
78+ void age_callout_queue ( int elapsed_time )
79+ {
7980 struct timeOutQueue * ptr ;
8081 struct timeOutQueue * _queue = NULL ;
81- struct timeOutQueue * last = NULL ;
82- int i = 0 ;
82+ struct timeOutQueue * last = NULL ;
83+ int i = 0 ;
8384
84- for (ptr = queue ; ptr ; ptr = ptr -> next ) {
85- if (ptr -> time > elapsed_time ) {
85+ for ( ptr = queue ; ptr ; ptr = ptr -> next ) {
86+ if ( ptr -> time > elapsed_time ) {
8687 ptr -> time -= elapsed_time ;
8788 break ;
88- } else {
89+ }
90+ else {
8991 elapsed_time -= ptr -> time ;
90- if (_queue == NULL )
92+ if ( _queue == NULL )
9193 _queue = ptr ;
92- last = ptr ;
93- }
94+ last = ptr ;
95+ }
9496 }
9597
9698 queue = ptr ;
97- if (last ) {
99+ if ( last ) {
98100 last -> next = NULL ;
99101 }
100102
101103 /* process existing events */
102- for (ptr = _queue ; ptr ; ptr = _queue , i ++ ) {
104+ for ( ptr = _queue ; ptr ; ptr = _queue , i ++ ) {
103105 _queue = _queue -> next ;
104- my_log (LOG_DEBUG , 0 , "About to call timeout %d (#%d)" , ptr -> id , i );
105- if (ptr -> func )
106- ptr -> func (ptr -> data );
107- free (ptr );
106+ my_log ( LOG_DEBUG , 0 , "About to call timeout %d (#%d)" , ptr -> id , i );
107+ if ( ptr -> func )
108+ ptr -> func ( ptr -> data );
109+ free ( ptr );
108110 }
109111}
110112
111113/**
112114 * Return in how many seconds age_callout_queue() would like to be called.
113115 * Return -1 if there are no events pending.
114116 */
115- int timer_nextTimer (void ) {
116- if ( queue ) {
117- if (queue -> time < 0 ) {
118- my_log ( LOG_WARNING , 0 , "timer_nextTimer top of queue says %d" ,
119- queue -> time );
117+ int timer_nextTimer ( void )
118+ {
119+ if ( queue ) {
120+ if ( queue -> time < 0 ) {
121+ my_log ( LOG_WARNING , 0 , "timer_nextTimer top of queue says %d" , queue -> time );
120122 return 0 ;
121123 }
122124 return queue -> time ;
@@ -130,14 +132,15 @@ int timer_nextTimer(void) {
130132 * @param action - The function to call on timeout.
131133 * @param data - Pointer to the function data to supply...
132134 */
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 ;
136139
137140 /* create a node */
138- node = (struct timeOutQueue * )malloc (sizeof (struct timeOutQueue ) );
139- if (node == 0 ) {
140- my_log (LOG_WARNING , 0 , "Malloc Failed in timer_settimer\n" );
141+ node = (struct timeOutQueue * ) malloc ( sizeof ( struct timeOutQueue ) );
142+ if ( node == 0 ) {
143+ my_log ( LOG_WARNING , 0 , "Malloc Failed in timer_settimer\n" );
141144 return -1 ;
142145 }
143146 node -> func = action ;
@@ -151,39 +154,38 @@ int timer_setTimer(int delay, timer_f action, void *data) {
151154 /* insert node in the queue */
152155
153156 /* if the queue is empty, insert the node and return */
154- if (!queue ) {
157+ if ( !queue ) {
155158 queue = node ;
156159 }
157160 else {
158161 /* chase the pointer looking for the right place */
159- while (ptr ) {
160- if (delay < ptr -> time ) {
162+ while ( ptr ) {
163+ if ( delay < ptr -> time ) {
161164 // We found the correct node
162165 node -> next = ptr ;
163- if (ptr == queue ) {
166+ if ( ptr == queue ) {
164167 queue = node ;
165168 }
166169 else {
167170 prev -> next = node ;
168171 }
169172 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 );
173174 debugQueue ();
174175 return node -> id ;
175- } else {
176+ }
177+ else {
176178 // 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 ;
180183 }
181184 i ++ ;
182185 }
183186 prev -> next = node ;
184187 }
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 );
187189 debugQueue ();
188190
189191 return node -> id ;
@@ -192,16 +194,17 @@ int timer_setTimer(int delay, timer_f action, void *data) {
192194/**
193195* returns the time until the timer is scheduled
194196*/
195- int timer_leftTimer (int timer_id ) {
197+ int timer_leftTimer ( int timer_id )
198+ {
196199 struct timeOutQueue * ptr ;
197- int left = 0 ;
200+ int left = 0 ;
198201
199- if (!timer_id )
202+ if ( !timer_id )
200203 return -1 ;
201204
202- for (ptr = queue ; ptr ; ptr = ptr -> next ) {
205+ for ( ptr = queue ; ptr ; ptr = ptr -> next ) {
203206 left += ptr -> time ;
204- if (ptr -> id == timer_id ) {
207+ if ( ptr -> id == timer_id ) {
205208 return left ;
206209 }
207210 }
@@ -211,11 +214,12 @@ int timer_leftTimer(int timer_id) {
211214/**
212215* clears the associated timer. Returns 1 if succeeded.
213216*/
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 ;
217221
218- if (!timer_id )
222+ if ( !timer_id )
219223 return 0 ;
220224
221225 prev = ptr = queue ;
@@ -226,44 +230,45 @@ int timer_clearTimer(int timer_id) {
226230 */
227231
228232 debugQueue ();
229- while (ptr ) {
230- if (ptr -> id == timer_id ) {
233+ while ( ptr ) {
234+ if ( ptr -> id == timer_id ) {
231235 /* got the right node */
232236
233237 /* unlink it from the queue */
234- if (ptr == queue )
238+ if ( ptr == queue )
235239 queue = queue -> next ;
236240 else
237241 prev -> next = ptr -> next ;
238242
239243 /* increment next node if any */
240- if (ptr -> next != 0 )
241- (ptr -> next )-> time += ptr -> time ;
244+ if ( ptr -> next != 0 )
245+ ( ptr -> next )-> time += ptr -> time ;
242246
243- if (ptr -> data )
244- free (ptr -> data );
245- my_log (LOG_DEBUG , 0 , "deleted timer %d (#%d)" , ptr -> id , i );
246- free (ptr );
247+ if ( ptr -> data )
248+ free ( ptr -> data );
249+ my_log ( LOG_DEBUG , 0 , "deleted timer %d (#%d)" , ptr -> id , i );
250+ free ( ptr );
247251 debugQueue ();
248252 return 1 ;
249253 }
250254 prev = ptr ;
251- ptr = ptr -> next ;
255+ ptr = ptr -> next ;
252256 i ++ ;
253257 }
254258 // If we get here, the timer was not deleted.
255- my_log (LOG_DEBUG , 0 , "failed to delete timer %d (#%d)" , timer_id , i );
259+ my_log ( LOG_DEBUG , 0 , "failed to delete timer %d (#%d)" , timer_id , i );
256260 debugQueue ();
257261 return 0 ;
258262}
259263
260264/**
261265 * debugging utility
262266 */
263- static void debugQueue (void ) {
264- struct timeOutQueue * ptr ;
267+ static void debugQueue ( void )
268+ {
269+ struct timeOutQueue * ptr ;
265270
266- for (ptr = queue ; ptr ; ptr = ptr -> next ) {
267- my_log (LOG_DEBUG , 0 , "(Id:%d, Time:%d) " , ptr -> id , ptr -> time );
271+ for ( ptr = queue ; ptr ; ptr = ptr -> next ) {
272+ my_log ( LOG_DEBUG , 0 , "(Id:%d, Time:%d) " , ptr -> id , ptr -> time );
268273 }
269274}
0 commit comments