1 Star 0 Fork 2

何吕 / volantmq

forked from JUMEI_ARCH / volantmq 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
tls.go 1.03 KB
Copy Edit Raw Blame History
hawklin authored 2018-04-28 16:33 . gofmt
package transport
import (
"crypto/tls"
"errors"
"net"
"os"
)
func NewTLSListener(inner net.Listener, config *tls.Config) *TLSListener {
l := new(TLSListener)
l.Listener = inner
l.config = config
return l
}
// TLSListener wraps standard tls listener.
type TLSListener struct {
net.Listener
config *tls.Config
}
// TLSConnection wraps standard tls connection and implements the File function.
type TLSConnection struct {
*tls.Conn
innerConn net.Conn
}
// Accept the next incoming connection and wraps it into tls Conn.
func (l *TLSListener) Accept() (net.Conn, error) {
c, err := l.Listener.Accept()
if err != nil {
return nil, err
}
return &TLSConnection{
tls.Server(c, l.config),
c,
}, nil
}
func (c *TLSConnection) File() (*os.File, error) {
switch c.innerConn.(type) {
case *net.TCPConn:
return c.innerConn.(*net.TCPConn).File()
case *net.UnixConn:
return c.innerConn.(*net.UnixConn).File()
case *net.UDPConn:
return c.innerConn.(*net.UDPConn).File()
}
return nil, errors.New("connection type not recognized.")
}
Go
1
https://gitee.com/kaifazhe/volantmq.git
git@gitee.com:kaifazhe/volantmq.git
kaifazhe
volantmq
volantmq
v0.0.4

Search

53164aa7 5694891 3bd8fe86 5694891