소스 검색

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)