| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *	BIRD -- I/O and event loop | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *	Can be freely distributed and used under the terms of the GNU GPL. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | #ifndef _BIRD_BFD_IO_H_
 | 
					
						
							|  |  |  | #define _BIRD_BFD_IO_H_
 | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | #include "nest/bird.h"
 | 
					
						
							|  |  |  | #include "lib/lists.h"
 | 
					
						
							|  |  |  | #include "lib/resource.h"
 | 
					
						
							|  |  |  | #include "lib/event.h"
 | 
					
						
							|  |  |  | #include "lib/socket.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-12 11:14:54 +02:00
										 |  |  | // #include "sysdep/unix/timer.h"
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct timer2 | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   resource r; | 
					
						
							|  |  |  |   void (*hook)(struct timer2 *); | 
					
						
							|  |  |  |   void *data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  |   btime expires;			/* 0=inactive */ | 
					
						
							|  |  |  |   uint randomize;			/* Amount of randomization */ | 
					
						
							|  |  |  |   uint recurrent;			/* Timer recurrence */ | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   int index; | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | } timer2; | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | btime current_time(void); | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ev2_schedule(event *e); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | timer2 *tm2_new(pool *p); | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | void tm2_set(timer2 *t, btime when); | 
					
						
							|  |  |  | void tm2_start(timer2 *t, btime after); | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | void tm2_stop(timer2 *t); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | static inline int | 
					
						
							|  |  |  | tm2_active(timer2 *t) | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  |   return t->expires != 0; | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | static inline btime  | 
					
						
							|  |  |  | tm2_remains(timer2 *t) | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  |   btime now = current_time(); | 
					
						
							|  |  |  |   return (t->expires > now) ? (t->expires - now) : 0; | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline timer2 * | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | tm2_new_init(pool *p, void (*hook)(struct timer2 *), void *data, uint rec, uint rand) | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   timer2 *t = tm2_new(p); | 
					
						
							|  |  |  |   t->hook = hook; | 
					
						
							|  |  |  |   t->data = data; | 
					
						
							|  |  |  |   t->recurrent = rec; | 
					
						
							|  |  |  |   t->randomize = rand; | 
					
						
							|  |  |  |   return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 22:33:48 +01:00
										 |  |  | static inline void | 
					
						
							|  |  |  | tm2_set_max(timer2 *t, btime when) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (when > t->expires) | 
					
						
							|  |  |  |     tm2_set(t, when); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  | static inline void | 
					
						
							|  |  |  | tm2_start_max(timer2 *t, btime after) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   btime rem = tm2_remains(t); | 
					
						
							| 
									
										
										
										
											2013-11-22 21:59:43 +01:00
										 |  |  |   tm2_start(t, MAX_(rem, after)); | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void sk_start(sock *s); | 
					
						
							|  |  |  | void sk_stop(sock *s); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-19 22:33:48 +01:00
										 |  |  | struct birdloop *birdloop_new(void); | 
					
						
							| 
									
										
										
										
											2013-10-05 20:12:28 +02:00
										 |  |  | void birdloop_start(struct birdloop *loop); | 
					
						
							|  |  |  | void birdloop_stop(struct birdloop *loop); | 
					
						
							| 
									
										
										
										
											2013-11-19 22:33:48 +01:00
										 |  |  | void birdloop_free(struct birdloop *loop); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | void birdloop_enter(struct birdloop *loop); | 
					
						
							|  |  |  | void birdloop_leave(struct birdloop *loop); | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | void birdloop_mask_wakeups(struct birdloop *loop); | 
					
						
							|  |  |  | void birdloop_unmask_wakeups(struct birdloop *loop); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-10 12:09:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-16 23:57:40 +02:00
										 |  |  | #endif /* _BIRD_BFD_IO_H_ */
 |