Преглед на файлове

Inject Dialer from ClusterConfig (#1376)

Initialize dialer during creating ClusterConfig

Signed-off-by: Rintaro Okamura <rintaro.okamura@gmail.com>
Rintaro Okamura преди 5 години
родител
ревизия
95d072f1b5
променени са 4 файла, в които са добавени 13 реда и са изтрити 2 реда
  1. 1 0
      AUTHORS
  2. 4 0
      cluster.go
  3. 7 2
      conn.go
  4. 1 0
      connectionpool.go

+ 1 - 0
AUTHORS

@@ -112,3 +112,4 @@ Karl Matthias <karl@matthias.org>
 Thomas Meson <zllak@hycik.org>
 Martin Sucha <martin.sucha@kiwi.com>; <git@mm.ms47.eu>
 Pavel Buchinchik <p.buchinchik@gmail.com>
+Rintaro Okamura <rintaro.okamura@gmail.com>

+ 4 - 0
cluster.go

@@ -144,6 +144,10 @@ type ClusterConfig struct {
 	// (default: 200 microseconds)
 	WriteCoalesceWaitTime time.Duration
 
+	// Dialer will be used to establish all connections created for this Cluster.
+	// If not provided, a default dialer configured with ConnectTimeout will be used.
+	Dialer *net.Dialer
+
 	// internal config for testing
 	disableControlConn bool
 }

+ 7 - 2
conn.go

@@ -99,6 +99,7 @@ type ConnConfig struct {
 	CQLVersion     string
 	Timeout        time.Duration
 	ConnectTimeout time.Duration
+	Dialer         *net.Dialer
 	Compressor     Compressor
 	Authenticator  Authenticator
 	AuthProvider   func(h *HostInfo) (Authenticator, error)
@@ -200,9 +201,13 @@ func (s *Session) dialWithoutObserver(ctx context.Context, host *HostInfo, cfg *
 		panic(fmt.Sprintf("host missing port: %v", port))
 	}
 
-	dialer := &net.Dialer{
-		Timeout: cfg.ConnectTimeout,
+	dialer := cfg.Dialer
+	if dialer == nil {
+		dialer = &net.Dialer{
+			Timeout: cfg.ConnectTimeout,
+		}
 	}
+
 	if cfg.Keepalive > 0 {
 		dialer.KeepAlive = cfg.Keepalive
 	}

+ 1 - 0
connectionpool.go

@@ -94,6 +94,7 @@ func connConfig(cfg *ClusterConfig) (*ConnConfig, error) {
 		CQLVersion:      cfg.CQLVersion,
 		Timeout:         cfg.Timeout,
 		ConnectTimeout:  cfg.ConnectTimeout,
+		Dialer:          cfg.Dialer,
 		Compressor:      cfg.Compressor,
 		Authenticator:   cfg.Authenticator,
 		AuthProvider:    cfg.AuthProvider,