1 #ifndef __TIMER_H_ 2 #define __TIMER_H_ 3 /*----------------------------------------------------------------------------*/ 4 #include "mtcp.h" 5 #include "tcp_stream.h" 6 #include <sys/time.h> 7 /*----------------------------------------------------------------------------*/ 8 #define RTO_HASH 2048 9 /*----------------------------------------------------------------------------*/ 10 #define TIMEVAL_ADD(a, b) \ 11 do { (a)->tv_sec += (b)->tv_sec; \ 12 if (((a)->tv_usec += (b)->tv_usec) > 1000000) { \ 13 (a)->tv_sec++; (a)->tv_usec -= 1000000; } \ 14 } while (0) 15 16 #define TIMEVAL_LT(a, b) \ 17 timercmp(a, b, <) 18 /*----------------------------------------------------------------------------*/ 19 struct timer { 20 int id; 21 struct timeval exp; /* expiration time */ 22 callback_t cb; 23 24 TAILQ_ENTRY(timer) timer_link; 25 }; 26 27 struct rto_hashstore 28 { 29 uint32_t rto_now_idx; // pointing the hs_table_s index 30 uint32_t rto_now_ts; // 31 32 TAILQ_HEAD(rto_head , tcp_stream) rto_list[RTO_HASH+1]; 33 }; 34 /*----------------------------------------------------------------------------*/ 35 struct rto_hashstore* 36 InitRTOHashstore(); 37 38 extern inline void 39 AddtoRTOList(mtcp_manager_t mtcp, tcp_stream *cur_stream); 40 41 extern inline void 42 RemoveFromRTOList(mtcp_manager_t mtcp, tcp_stream *cur_stream); 43 44 extern inline void 45 AddtoTimewaitList(mtcp_manager_t mtcp, tcp_stream *cur_stream, uint32_t cur_ts); 46 47 extern inline void 48 RemoveFromTimewaitList(mtcp_manager_t mtcp, tcp_stream *cur_stream); 49 50 extern inline void 51 AddtoTimeoutList(mtcp_manager_t mtcp, tcp_stream *cur_stream); 52 53 extern inline void 54 RemoveFromTimeoutList(mtcp_manager_t mtcp, tcp_stream *cur_stream); 55 56 extern inline void 57 UpdateTimeoutList(mtcp_manager_t mtcp, tcp_stream *cur_stream); 58 59 extern inline void 60 UpdateRetransmissionTimer(mtcp_manager_t mtcp, 61 tcp_stream *cur_stream, uint32_t cur_ts); 62 63 void 64 CheckRtmTimeout(mtcp_manager_t mtcp, uint32_t cur_ts, int thresh); 65 66 void 67 CheckTimewaitExpire(mtcp_manager_t mtcp, uint32_t cur_ts, int thresh); 68 69 void 70 CheckConnectionTimeout(mtcp_manager_t mtcp, uint32_t cur_ts, int thresh); 71 72 void 73 DelTimer(mtcp_manager_t mtcp, struct timer *timer); 74 /*----------------------------------------------------------------------------*/ 75 #endif /* __TIMER_H_ */ 76