ing
This commit is contained in:
parent
49eee11b7f
commit
1c8bef954e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user