From 54c3f20e32bda2ed07622f4eeaca9aa22b15e83c Mon Sep 17 00:00:00 2001 From: wangyu Date: Fri, 4 Aug 2017 23:08:45 +0800 Subject: [PATCH] added about to exit --- common.cpp | 15 ++++++++++++--- common.h | 2 +- log.cpp | 4 +++- main.cpp | 27 +++++++++++++++------------ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/common.cpp b/common.cpp index 28959ce..2810285 100644 --- a/common.cpp +++ b/common.cpp @@ -10,6 +10,7 @@ +int about_to_exit=0; raw_mode_t raw_mode=mode_faketcp; unordered_map raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}}; @@ -72,7 +73,15 @@ int clear_iptables_rule() { char buf[300]="iptables -D "; strcat(buf,iptables_rule); - system(buf); + if(system(buf)==0) + { + mylog(log_warn,"iptables rule cleared\n",buf); + } + else + { + mylog(log_error,"auto added iptables failed by: %s\n",buf); + } + } return 0; } @@ -209,8 +218,8 @@ void myexit(int a) } void signal_handler(int sig) { - - myexit(0); + about_to_exit=1; + // myexit(0); } int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len) diff --git a/common.h b/common.h index f5907cb..cae85a1 100644 --- a/common.h +++ b/common.h @@ -93,7 +93,7 @@ const u32_t client_conn_timeout=10000; //const uint32_t server_conn_timeout=conv_timeout+60000;//this should be 60s+ longer than conv_timeout,so that conv_manager can destruct convs gradually,to avoid latency glicth const u32_t server_conn_timeout=conv_timeout+10000;//for test - +extern int about_to_exit; enum raw_mode_t{mode_faketcp=0,mode_udp,mode_icmp,mode_end}; extern raw_mode_t raw_mode; diff --git a/log.cpp b/log.cpp index 9263dfc..31255e1 100755 --- a/log.cpp +++ b/log.cpp @@ -40,7 +40,9 @@ void log0(const char * file,const char * function,int line,int level,const char* fflush(stdout); if(log_level==log_fatal) - myexit(-1); + { + about_to_exit=1; + } } void log_bare(int level,const char* str, ...) diff --git a/main.cpp b/main.cpp index 4ea4bcf..c2a8522 100755 --- a/main.cpp +++ b/main.cpp @@ -750,7 +750,7 @@ int parse_safer(conn_info_t &conn_info,const char * input,int input_len,char* &d if(h_oppiste_id!=conn_info.oppsite_id||h_my_id!=conn_info.my_id) { - mylog(log_warn,"id and oppsite_id verification failed %x %x %x %x \n",h_oppiste_id,conn_info.oppsite_id,h_my_id,conn_info.my_id); + mylog(log_debug,"id and oppsite_id verification failed %x %x %x %x \n",h_oppiste_id,conn_info.oppsite_id,h_my_id,conn_info.my_id); return -1; } @@ -766,13 +766,13 @@ int parse_safer(conn_info_t &conn_info,const char * input,int input_len,char* &d if(data[0]!='h'&&data[0]!='d') { - mylog(log_warn,"first byte is not h or d ,%x\n",data[0]); + mylog(log_debug,"first byte is not h or d ,%x\n",data[0]); return -1; } if(len<0) { - mylog(log_error,"len <0 ,%d\n",len); + mylog(log_debug,"len <0 ,%d\n",len); return -1; } @@ -1633,7 +1633,7 @@ int server_on_raw_recv_ready(conn_info_t &conn_info) //pack_u64(conn_info.raw_info.recv_info.src_ip,conn_info.raw_info.recv_info.src_port); - mylog(log_info, "new conv conv_id=%x, assigned fd=%d\n", + mylog(log_info, "[%s]new conv conv_id=%x, assigned fd=%d\n",ip_port, tmp_conv_id, new_udp_fd); @@ -1921,6 +1921,7 @@ int client_event_loop() mylog(log_debug,"send_raw : from %x %d to %x %d\n",send_info.src_ip,send_info.src_port,send_info.dst_ip,send_info.dst_port); while(1)//////////////////////// { + if(about_to_exit) myexit(0); epoll_trigger_counter++; int nfds = epoll_wait(epollfd, events, max_events, 180 * 1000); if (nfds < 0) { //allow zero @@ -2096,6 +2097,8 @@ int server_event_loop() while(1)//////////////////////// { + if(about_to_exit) myexit(0); + int nfds = epoll_wait(epollfd, events, max_events, 180 * 1000); if (nfds < 0) { //allow zero mylog(log_fatal,"epoll_wait return %d\n", nfds); @@ -2116,8 +2119,8 @@ int server_event_loop() //current_time_rough=get_current_time(); if(debug_flag) { - end_time=get_current_time()-begin_time; - mylog(log_debug,"conn_manager.clear_inactive(),%llu,%llu,%llu\n",begin_time,end_time,end_time-begin_time); + end_time=get_current_time(); + mylog(log_debug,"timer_fd,%llu,%llu,%llu\n",begin_time,end_time,end_time-begin_time); } mylog(log_trace,"epoll_trigger_counter: %d \n",epoll_trigger_counter); @@ -2130,8 +2133,8 @@ int server_event_loop() server_on_raw_recv_multi(); if(debug_flag) { - end_time=get_current_time()-begin_time; - mylog(log_debug,"conn_manager.clear_inactive(),%llu,%llu,%llu \n",begin_time,end_time,end_time-begin_time); + end_time=get_current_time(); + mylog(log_debug,"raw_recv_fd,%llu,%llu,%llu \n",begin_time,end_time,end_time-begin_time); } } else if ((events[idx].data.u64 >>32u) == 2u) @@ -2158,8 +2161,8 @@ int server_event_loop() if(debug_flag) { - end_time=get_current_time()-begin_time; - mylog(log_debug,"conn_manager.clear_inactive(),%llu,%llu,%llu \n",begin_time,end_time,end_time-begin_time); + end_time=get_current_time(); + mylog(log_debug,"(events[idx].data.u64 >>32u) == 2u ,%llu,%llu,%llu \n",begin_time,end_time,end_time-begin_time); } } else if ((events[idx].data.u64 >>32u) == 1u) @@ -2224,8 +2227,8 @@ int server_event_loop() if(debug_flag) { - end_time=get_current_time()-begin_time; - mylog(log_debug,"conn_manager.clear_inactive(),%lld,%lld,%lld \n",begin_time,end_time,end_time-begin_time); + end_time=get_current_time(); + mylog(log_debug,"(events[idx].data.u64 >>32u) == 1u,%lld,%lld,%lld \n",begin_time,end_time,end_time-begin_time); } } else