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.
@@ -53,44 +52,47 @@ static void debugQueue(void);
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
6667 while (queue ) {
67- p = queue ;
68+ p = queue ;
6869 queue = queue -> next ;
6970 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
8485 for (ptr = queue ; ptr ; ptr = ptr -> next ) {
8586 if (ptr -> time > elapsed_time ) {
8687 ptr -> time -= elapsed_time ;
8788 break ;
88- } else {
89+ }
90+ else {
8991 elapsed_time -= ptr -> time ;
9092 if (_queue == NULL )
9193 _queue = ptr ;
92- last = ptr ;
93- }
94+ last = ptr ;
95+ }
9496 }
9597
9698 queue = ptr ;
@@ -103,7 +105,7 @@ void age_callout_queue(int elapsed_time) {
103105 _queue = _queue -> next ;
104106 my_log (LOG_DEBUG , 0 , "About to call timeout %d (#%d)" , ptr -> id , i );
105107 if (ptr -> func )
106- ptr -> func (ptr -> data );
108+ ptr -> func (ptr -> data );
107109 free (ptr );
108110 }
109111}
@@ -112,11 +114,11 @@ void age_callout_queue(int elapsed_time) {
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 ) {
117+ int timer_nextTimer (void )
118+ {
116119 if (queue ) {
117120 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 );
120122 return 0 ;
121123 }
122124 return queue -> time ;
@@ -130,12 +132,13 @@ 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 ));
141+ node = (struct timeOutQueue * ) malloc (sizeof (struct timeOutQueue ));
139142 if (node == 0 ) {
140143 my_log (LOG_WARNING , 0 , "Malloc Failed in timer_settimer\n" );
141144 return -1 ;
@@ -167,23 +170,22 @@ int timer_setTimer(int delay, timer_f action, void *data) {
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,9 +194,10 @@ 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
199202 if (!timer_id )
200203 return -1 ;
@@ -211,9 +214,10 @@ 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
218222 if (!timer_id )
219223 return 0 ;
@@ -248,7 +252,7 @@ int timer_clearTimer(int timer_id) {
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.
@@ -260,8 +264,9 @@ int timer_clearTimer(int timer_id) {
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
266271 for (ptr = queue ; ptr ; ptr = ptr -> next ) {
267272 my_log (LOG_DEBUG , 0 , "(Id:%d, Time:%d) " , ptr -> id , ptr -> time );
0 commit comments