new option hb-mode

This commit is contained in:
wangyu- 2017-11-07 01:07:32 -06:00
parent d487ca57f7
commit 50f682daf4
3 changed files with 35 additions and 10 deletions

@ -9,6 +9,7 @@
int mtu_warn=1375;//if a packet larger than mtu warn is receviced,there will be a warning
char hb_buf[buf_len];
int hb_len=1200;
@ -242,8 +243,10 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
mylog(log_debug,"heartbeat sent <%x,%x>\n",conn_info.oppsite_id,conn_info.my_id);
send_safer(conn_info,'h',hb_buf,hb_len);/////////////send
if(hb_mode==0)
send_safer(conn_info,'h',hb_buf,0);/////////////send
else
send_safer(conn_info,'h',hb_buf,hb_len);
conn_info.last_hb_sent_time=get_current_time();
return 0;
}
@ -285,8 +288,10 @@ int server_on_timer_multi(conn_info_t &conn_info,char * ip_port) //for server.
return 0;
}
send_safer(conn_info,'h',hb_buf,hb_len); /////////////send
if(hb_mode==0)
send_safer(conn_info,'h',hb_buf,0); /////////////send
else
send_safer(conn_info,'h',hb_buf,hb_len);
conn_info.last_hb_sent_time=get_current_time();
mylog(log_debug,"heart beat sent<%x,%x>\n",conn_info.my_id,conn_info.oppsite_id);
@ -442,7 +447,8 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
{
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
conn_info.last_hb_recv_time=get_current_time();
if(hb_mode==0)
conn_info.last_hb_recv_time=get_current_time();
//u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0]));
u32_t tmp_conv_id;
@ -790,7 +796,8 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
tmp_conv_id=ntohl(tmp_conv_id);
conn_info.last_hb_recv_time = get_current_time();
if(hb_mode==0)
conn_info.last_hb_recv_time = get_current_time();
mylog(log_trace, "conv:%u\n", tmp_conv_id);
if (!conn_info.blob->conv_manager.is_conv_used(tmp_conv_id)) {
@ -916,11 +923,14 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
//my_id=conn_info.my_id;
//oppsite_id=conn_info.oppsite_id;
conn_info.last_hb_recv_time = get_current_time();
conn_info.last_hb_sent_time = conn_info.last_hb_recv_time;//=get_current_time()
send_safer(conn_info, 'h',hb_buf, hb_len); /////////////send
if(hb_mode==0)
send_safer(conn_info,'h',hb_buf,0);/////////////send
else
send_safer(conn_info,'h',hb_buf,hb_len);
mylog(log_info, "[%s]changed state to server_ready\n",ip_port);
conn_info.blob->anti_replay.re_init();
@ -980,8 +990,14 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
//ori_conn_info.state.server_current_state=server_ready;
ori_conn_info.recover(conn_info);
send_safer(ori_conn_info, 'h',hb_buf, hb_len);
//send_safer(ori_conn_info, 'h',hb_buf, hb_len);
//ori_conn_info.blob->anti_replay.re_init();
if(hb_mode==0)
send_safer(ori_conn_info,'h',hb_buf,0);/////////////send
else
send_safer(ori_conn_info,'h',hb_buf,hb_len);
ori_conn_info.last_hb_recv_time=get_current_time();

@ -13,6 +13,8 @@
#include "fd_manager.h"
int hb_mode=1;
fd_manager_t fd_manager;
char local_ip[100]="0.0.0.0", remote_ip[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_ip for -r option,source for --source-ip
@ -247,6 +249,7 @@ void process_arg(int argc, char *argv[]) //process all options
{"force-sock-buf", no_argument, 0, 1},
{"random-drop", required_argument, 0, 1},
{"fifo", required_argument, 0, 1},
{"hb-mode", required_argument, 0, 1},
{NULL, 0, 0, 0}
};
@ -589,6 +592,12 @@ void process_arg(int argc, char *argv[]) //process all options
{
mylog(log_info,"configuration loaded from %s\n",optarg);
}
else if(strcmp(long_options[option_index].name,"hb-mode")==0)
{
sscanf(optarg,"%d",&hb_mode);
assert(hb_mode==0||hb_mode==1);
mylog(log_info,"hb_mode =%d \n",hb_mode);
}
else
{

2
misc.h

@ -13,7 +13,7 @@
#include "log.h"
#include "network.h"
extern int hb_mode;
const u32_t max_handshake_conn_num=10000;
const u32_t max_ready_conn_num=1000;