added about to exit

This commit is contained in:
wangyu 2017-08-04 23:08:45 +08:00
parent 343c7b2a29
commit 54c3f20e32
4 changed files with 31 additions and 17 deletions

View File

@ -10,6 +10,7 @@
int about_to_exit=0;
raw_mode_t raw_mode=mode_faketcp;
unordered_map<int, const char*> 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)

View File

@ -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;

View File

@ -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, ...)

View File

@ -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