瀏覽代碼

conn: if we dont have a timeout use WithCancel

Chris Bannister 9 年之前
父節點
當前提交
6354e9dca8
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      conn.go

+ 9 - 1
conn.go

@@ -202,7 +202,15 @@ func Connect(host *HostInfo, addr string, cfg *ConnConfig,
 		c.setKeepalive(cfg.Keepalive)
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
+	var (
+		ctx    context.Context
+		cancel func()
+	)
+	if c.timeout > 0 {
+		ctx, cancel = context.WithTimeout(context.Background(), c.timeout)
+	} else {
+		ctx, cancel = context.WithCancel(context.Background())
+	}
 	defer cancel()
 
 	frameTicker := make(chan struct{}, 1)