Sfoglia il codice sorgente

conn: dont mutate the conn config

The conn config is shared by the connection pool.

Updates #519
Chris Bannister 10 anni fa
parent
commit
75ef4c239a
1 ha cambiato i file con 7 aggiunte e 6 eliminazioni
  1. 7 6
      conn.go

+ 7 - 6
conn.go

@@ -160,18 +160,19 @@ func Connect(addr string, cfg *ConnConfig, errorHandler ConnErrorHandler, sessio
 		headerSize = 9
 	}
 
-	if cfg.NumStreams <= 0 || cfg.NumStreams >= maxStreams {
-		cfg.NumStreams = maxStreams
+	streams := cfg.NumStreams
+	if streams <= 0 || streams >= maxStreams {
+		streams = maxStreams
 	} else {
-		cfg.NumStreams++
+		streams++
 	}
 
 	c := &Conn{
 		conn:         conn,
 		r:            bufio.NewReader(conn),
 		cfg:          cfg,
-		uniq:         make(chan int, cfg.NumStreams),
-		calls:        make([]callReq, cfg.NumStreams),
+		uniq:         make(chan int, streams),
+		calls:        make([]callReq, streams),
 		timeout:      cfg.Timeout,
 		version:      uint8(cfg.ProtoVersion),
 		addr:         conn.RemoteAddr().String(),
@@ -189,7 +190,7 @@ func Connect(addr string, cfg *ConnConfig, errorHandler ConnErrorHandler, sessio
 
 	// reserve stream 0 incase cassandra returns an error on it without us sending
 	// a request.
-	for i := 1; i < cfg.NumStreams; i++ {
+	for i := 1; i < streams; i++ {
 		c.calls[i].resp = make(chan error)
 		c.uniq <- i
 	}