crypto/...: changes to address some of bug 2841.
This change addresses a subset of the issues raised in bug 2841. R=rsc CC=golang-dev https://golang.org/cl/5629044
This commit is contained in:
parent
8ee5e4091a
commit
afe534d19b
28
tls.go
28
tls.go
@ -33,16 +33,16 @@ func Client(conn net.Conn, config *Config) *Conn {
|
|||||||
return &Conn{conn: conn, config: config, isClient: true}
|
return &Conn{conn: conn, config: config, isClient: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Listener implements a network listener (net.Listener) for TLS connections.
|
// A listener implements a network listener (net.Listener) for TLS connections.
|
||||||
type Listener struct {
|
type listener struct {
|
||||||
listener net.Listener
|
net.Listener
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accept waits for and returns the next incoming TLS connection.
|
// Accept waits for and returns the next incoming TLS connection.
|
||||||
// The returned connection c is a *tls.Conn.
|
// The returned connection c is a *tls.Conn.
|
||||||
func (l *Listener) Accept() (c net.Conn, err error) {
|
func (l *listener) Accept() (c net.Conn, err error) {
|
||||||
c, err = l.listener.Accept()
|
c, err = l.Listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -50,28 +50,22 @@ func (l *Listener) Accept() (c net.Conn, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the listener.
|
|
||||||
func (l *Listener) Close() error { return l.listener.Close() }
|
|
||||||
|
|
||||||
// Addr returns the listener's network address.
|
|
||||||
func (l *Listener) Addr() net.Addr { return l.listener.Addr() }
|
|
||||||
|
|
||||||
// NewListener creates a Listener which accepts connections from an inner
|
// NewListener creates a Listener which accepts connections from an inner
|
||||||
// Listener and wraps each connection with Server.
|
// Listener and wraps each connection with Server.
|
||||||
// The configuration config must be non-nil and must have
|
// The configuration config must be non-nil and must have
|
||||||
// at least one certificate.
|
// at least one certificate.
|
||||||
func NewListener(listener net.Listener, config *Config) (l *Listener) {
|
func NewListener(inner net.Listener, config *Config) net.Listener {
|
||||||
l = new(Listener)
|
l := new(listener)
|
||||||
l.listener = listener
|
l.Listener = inner
|
||||||
l.config = config
|
l.config = config
|
||||||
return
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen creates a TLS listener accepting connections on the
|
// Listen creates a TLS listener accepting connections on the
|
||||||
// given network address using net.Listen.
|
// given network address using net.Listen.
|
||||||
// The configuration config must be non-nil and must have
|
// The configuration config must be non-nil and must have
|
||||||
// at least one certificate.
|
// at least one certificate.
|
||||||
func Listen(network, laddr string, config *Config) (*Listener, error) {
|
func Listen(network, laddr string, config *Config) (net.Listener, error) {
|
||||||
if config == nil || len(config.Certificates) == 0 {
|
if config == nil || len(config.Certificates) == 0 {
|
||||||
return nil, errors.New("tls.Listen: no certificates in configuration")
|
return nil, errors.New("tls.Listen: no certificates in configuration")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user