From 1c8bef954e49daa2b7b1998483651297b3f7bded Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 30 Nov 2017 18:57:09 +0900 Subject: [PATCH] ing --- client/socket.go | 11 +---------- client/socket_builder.go | 2 ++ client/socket_builders.go | 8 ++++++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/socket.go b/client/socket.go index 370ea4a..d1a661c 100644 --- a/client/socket.go +++ b/client/socket.go @@ -1,7 +1,6 @@ package client import ( - "crypto/tls" "net" "sync" @@ -39,16 +38,8 @@ func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) { network := sb.GetNetwork() address := sb.GetAddress() - tlsConfig := sb.GetTLSConfig() - var conn net.Conn - var err error - - if nil == tlsConfig { - conn, err = d.Dial(network, address) - } else { - conn, err = tls.DialWithDialer(d, network, address, tlsConfig) - } + conn, err := sb.Dial(d, network, address) if nil != err { return nil, err diff --git a/client/socket_builder.go b/client/socket_builder.go index 8de6f86..148db21 100644 --- a/client/socket_builder.go +++ b/client/socket_builder.go @@ -12,6 +12,8 @@ type SocketBuilder interface { SocketContext(parent cuc.Context) SocketContext SocketHandler() SocketHandler + Dial(dialer *net.Dialer, network, address string) (net.Conn, error) + GetNetwork() string GetAddress() string GetTLSConfig() *tls.Config diff --git a/client/socket_builders.go b/client/socket_builders.go index 696e49d..12c53f1 100644 --- a/client/socket_builders.go +++ b/client/socket_builders.go @@ -41,6 +41,14 @@ func (sb *SocketBuilders) GetTLSConfig() *tls.Config { return sb.TLSConfig } +func (sb *SocketBuilders) Dial(dialer *net.Dialer, network, address string) (net.Conn, error) { + if nil == sb.TLSConfig { + return dialer.Dial(network, address) + } + + return tls.DialWithDialer(dialer, network, address, sb.TLSConfig) +} + func (sb *SocketBuilders) GetKeepAlive() time.Duration { return sb.KeepAlive }