|
@@ -28,6 +28,7 @@
|
|
#include "shm_mem.h"
|
|
#include "shm_mem.h"
|
|
#endif
|
|
#endif
|
|
#include "sr_module.h"
|
|
#include "sr_module.h"
|
|
|
|
+#include "timer.h"
|
|
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
@@ -230,6 +231,22 @@ int main_loop()
|
|
#endif
|
|
#endif
|
|
/* only one address */
|
|
/* only one address */
|
|
if (udp_init(addresses[0],port_no)==-1) goto error;
|
|
if (udp_init(addresses[0],port_no)==-1) goto error;
|
|
|
|
+
|
|
|
|
+ /* we need another process to act as the timer*/
|
|
|
|
+ if (timer_list){
|
|
|
|
+ if ((pid=fork())<0){
|
|
|
|
+ LOG(L_CRIT, "main_loop: Cannot fork\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ if (pid==0){
|
|
|
|
+ /* child */
|
|
|
|
+ /* timer!*/
|
|
|
|
+ for(;;){
|
|
|
|
+ sleep(TIMER_TICK);
|
|
|
|
+ timer_ticker();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
/* receive loop */
|
|
/* receive loop */
|
|
udp_rcv_loop();
|
|
udp_rcv_loop();
|
|
}else{
|
|
}else{
|
|
@@ -252,11 +269,16 @@ int main_loop()
|
|
close(udp_sock); /*parent*/
|
|
close(udp_sock); /*parent*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- for(;;){
|
|
|
|
- /* debug: instead of doing something usefull */
|
|
|
|
- /* (placeholder for timers, etc.) */
|
|
|
|
- sleep(10);
|
|
|
|
|
|
+ if (timer_list){
|
|
|
|
+ for(;;){
|
|
|
|
+ /* debug: instead of doing something usefull */
|
|
|
|
+ /* (placeholder for timers, etc.) */
|
|
|
|
+ sleep(TIMER_TICK);
|
|
|
|
+ /* if we received a signal => TIMER_TICK may have not elapsed*/
|
|
|
|
+ timer_ticker();
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ for(;;) sleep(LONG_SLEEP);
|
|
}
|
|
}
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
@@ -309,8 +331,9 @@ static void sig_usr(int signo)
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
int main(int argc, char** argv)
|
|
int main(int argc, char** argv)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -332,6 +355,7 @@ int main(int argc, char** argv)
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/* process command line (get port no, cfg. file path etc) */
|
|
/* process command line (get port no, cfg. file path etc) */
|
|
opterr=0;
|
|
opterr=0;
|
|
options=
|
|
options=
|
|
@@ -543,7 +567,6 @@ int main(int argc, char** argv)
|
|
if ( daemonize(argv[0]) <0 ) goto error;
|
|
if ( daemonize(argv[0]) <0 ) goto error;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
return main_loop();
|
|
return main_loop();
|
|
|
|
|
|
|
|
|