mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
wss: optimize server code
This commit is contained in:
1 parent
63caac133d
commit
346db3338e
5 files changed
+30
-31
No files matched your search
@@ -76,22 +76,20 @@ func (s *Trojan) ListenAndServe() {
|
||||
|
||||
// Serve serves a connection.
|
||||
func (s *Trojan) Serve(c net.Conn) {
|
||||
defer c.Close()
|
||||
|
||||
if c, ok := c.(*net.TCPConn); ok {
|
||||
c.SetKeepAlive(true)
|
||||
}
|
||||
|
||||
if s.withTLS {
|
||||
tlsConn := tls.Server(c, s.tlsConfig)
|
||||
defer tlsConn.Close()
|
||||
err := tlsConn.Handshake()
|
||||
if err != nil {
|
||||
if err := tlsConn.Handshake(); err != nil {
|
||||
tlsConn.Close()
|
||||
log.F("[trojan] error in tls handshake: %s", err)
|
||||
return
|
||||
}
|
||||
c = tlsConn
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
headBuf := pool.GetBytesBuffer()
|
||||
defer pool.PutBytesBuffer(headBuf)
|
||||
|
||||
Reference in new issue
Block a user