(1)新增心跳检测发送间隔和超时时间的配置

This commit is contained in:
Hurricanezwf
2016-02-05 14:36:04 +08:00
parent 5d6f37aa82
commit 04c26d1c31
6 changed files with 26 additions and 21 deletions

View File

@@ -11,16 +11,16 @@ import (
// common config
var (
ServerAddr string = "0.0.0.0"
ServerPort int64 = 7000
LogFile string = "./frpc.log"
LogLevel string = "warn"
LogWay string = "file"
ServerAddr string = "0.0.0.0"
ServerPort int64 = 7000
LogFile string = "./frpc.log"
LogLevel string = "warn"
LogWay string = "file"
HeartBeatInterval int64 = 5
)
var ProxyClients map[string]*models.ProxyClient = make(map[string]*models.ProxyClient)
func LoadConf(confFile string) (err error) {
var tmpStr string
var ok bool
@@ -56,6 +56,11 @@ func LoadConf(confFile string) (err error) {
LogWay = tmpStr
}
tmpStr, ok = conf.Get("common", "heartbeat_interval")
if ok {
HeartBeatInterval, _ = strconv.ParseInt(tmpStr, 10, 64)
}
// servers
for name, section := range conf {
if name != "common" {

View File

@@ -11,10 +11,6 @@ import (
"frp/pkg/utils/log"
)
const (
heartbeatDuration = 2 //心跳检测时间间隔,单位秒
)
var isHeartBeatContinue bool = true
func ControlProcess(cli *models.ProxyClient, wait *sync.WaitGroup) {
@@ -114,7 +110,7 @@ func loginToServer(cli *models.ProxyClient) (connection *conn.Conn) {
func startHeartBeat(con *conn.Conn) {
isHeartBeatContinue = true
for {
time.Sleep(heartbeatDuration * time.Second)
time.Sleep(time.Duration(HeartBeatInterval) * time.Second)
if isHeartBeatContinue { // 把isHeartBeatContinue放在这里是为了防止SIGPIPE
err := con.Write("\r\n")
//log.Debug("send heart beat to server!")