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
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

View File

@ -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

View File

@ -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
}