Browse Source

Update keepalive in the dialer (#1150)

Keerthan Reddy Mala 7 years ago
parent
commit
045d8d6abc
1 changed files with 3 additions and 17 deletions
  1. 3 17
      conn.go

+ 3 - 17
conn.go

@@ -173,6 +173,9 @@ func (s *Session) dial(host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHa
 	dialer := &net.Dialer{
 		Timeout: cfg.ConnectTimeout,
 	}
+	if cfg.Keepalive > 0 {
+		dialer.KeepAlive = cfg.Keepalive
+	}
 
 	// TODO(zariel): handle ipv6 zone
 	addr := (&net.TCPAddr{IP: ip, Port: port}).String()
@@ -207,10 +210,6 @@ func (s *Session) dial(host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHa
 		frameObserver: s.frameObserver,
 	}
 
-	if cfg.Keepalive > 0 {
-		c.setKeepalive(cfg.Keepalive)
-	}
-
 	var (
 		ctx    context.Context
 		cancel func()
@@ -1093,19 +1092,6 @@ func (c *Conn) executeBatch(batch *Batch) *Iter {
 	}
 }
 
-func (c *Conn) setKeepalive(d time.Duration) error {
-	if tc, ok := c.conn.(*net.TCPConn); ok {
-		err := tc.SetKeepAlivePeriod(d)
-		if err != nil {
-			return err
-		}
-
-		return tc.SetKeepAlive(true)
-	}
-
-	return nil
-}
-
 func (c *Conn) query(statement string, values ...interface{}) (iter *Iter) {
 	q := c.session.Query(statement, values...).Consistency(One)
 	return c.executeQuery(q)