Commit 1348c655 authored by Zhu Yong's avatar Zhu Yong Committed by GitHub
Browse files

Merge pull request #11 from yongzhy/master

Add network Timeout for ClientOption.
parents bc9e3d24 04d381dc
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ type ClientOptions struct {
	User    int64  // User Id
	Hmac    []byte
	UseSSL  bool  // Use SSL connection, or plain connection
	Timeout int64 // Network timeout in millisecond
}

// MessageType defines the top level kinetic command message type.
+7 −2
Original line number Diff line number Diff line
@@ -72,17 +72,22 @@ type networkService struct {
func newNetworkService(op ClientOptions) (*networkService, error) {
	var conn net.Conn
	var err error
	if op.Timeout > 0 {
		networkTimeout = time.Duration(op.Timeout) * time.Millisecond
	}

	target := fmt.Sprintf("%s:%d", op.Host, op.Port)
	if op.UseSSL {
		// TODO: Need to enable verify certification later
		config := tls.Config{InsecureSkipVerify: true}
		conn, err = tls.Dial("tcp", target, &config)
		d := &net.Dialer{Timeout: networkTimeout}
		conn, err = tls.DialWithDialer(d, "tcp", target, &config)
	} else {
		conn, err = net.DialTimeout("tcp", target, networkTimeout)
	}

	if err != nil {
		klog.Panic("Can't establish connection to ", op.Host, err)
		klog.Error("Can't establish connection to ", op.Host, err)
		return nil, err
	}