This commit is contained in:
crusader 2017-11-30 18:57:09 +09:00
parent 49eee11b7f
commit 1c8bef954e
3 changed files with 11 additions and 10 deletions

View File

@ -1,7 +1,6 @@
package client package client
import ( import (
"crypto/tls"
"net" "net"
"sync" "sync"
@ -39,16 +38,8 @@ func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) {
network := sb.GetNetwork() network := sb.GetNetwork()
address := sb.GetAddress() address := sb.GetAddress()
tlsConfig := sb.GetTLSConfig()
var conn net.Conn conn, err := sb.Dial(d, network, address)
var err error
if nil == tlsConfig {
conn, err = d.Dial(network, address)
} else {
conn, err = tls.DialWithDialer(d, network, address, tlsConfig)
}
if nil != err { if nil != err {
return nil, err return nil, err

View File

@ -12,6 +12,8 @@ type SocketBuilder interface {
SocketContext(parent cuc.Context) SocketContext SocketContext(parent cuc.Context) SocketContext
SocketHandler() SocketHandler SocketHandler() SocketHandler
Dial(dialer *net.Dialer, network, address string) (net.Conn, error)
GetNetwork() string GetNetwork() string
GetAddress() string GetAddress() string
GetTLSConfig() *tls.Config GetTLSConfig() *tls.Config

View File

@ -41,6 +41,14 @@ func (sb *SocketBuilders) GetTLSConfig() *tls.Config {
return sb.TLSConfig 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 { func (sb *SocketBuilders) GetKeepAlive() time.Duration {
return sb.KeepAlive return sb.KeepAlive
} }