浏览代码

Merge pull request #1643 from kzinglzy/fix-keepalive-doc

fix `config.net.keepalive`
Vlad Gorodetsky 5 年之前
父节点
当前提交
18d3a27547
共有 2 个文件被更改,包括 3 次插入9 次删除
  1. 3 4
      config.go
  2. 0 5
      config_test.go

+ 3 - 4
config.go

@@ -96,8 +96,9 @@ type Config struct {
 			GSSAPI GSSAPIConfig
 		}
 
-		// KeepAlive specifies the keep-alive period for an active network connection.
-		// If zero, keep-alives are disabled. (default is 0: disabled).
+		// KeepAlive specifies the keep-alive period for an active network connection (defaults to 0).
+		// If zero or positive, keep-alives are enabled.
+		// If negative, keep-alives are disabled.
 		KeepAlive time.Duration
 
 		// LocalAddr is the local address to use when dialing an
@@ -537,8 +538,6 @@ func (c *Config) Validate() error {
 		return ConfigurationError("Net.ReadTimeout must be > 0")
 	case c.Net.WriteTimeout <= 0:
 		return ConfigurationError("Net.WriteTimeout must be > 0")
-	case c.Net.KeepAlive < 0:
-		return ConfigurationError("Net.KeepAlive must be >= 0")
 	case c.Net.SASL.Enable:
 		if c.Net.SASL.Mechanism == "" {
 			c.Net.SASL.Mechanism = SASLTypePlaintext

+ 0 - 5
config_test.go

@@ -67,11 +67,6 @@ func TestNetConfigValidates(t *testing.T) {
 				cfg.Net.WriteTimeout = 0
 			},
 			"Net.WriteTimeout must be > 0"},
-		{"KeepAlive",
-			func(cfg *Config) {
-				cfg.Net.KeepAlive = -1
-			},
-			"Net.KeepAlive must be >= 0"},
 		{"SASL.User",
 			func(cfg *Config) {
 				cfg.Net.SASL.Enable = true