1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-05 13:40:55 +00:00
Beego/grace/conn.go

39 lines
506 B
Go

package grace
import (
"errors"
"net"
"sync"
)
type graceConn struct {
net.Conn
server *Server
m sync.Mutex
closed bool
}
func (c *graceConn) Close() (err error) {
defer func() {
if r := recover(); r != nil {
switch x := r.(type) {
case string:
err = errors.New(x)
case error:
err = x
default:
err = errors.New("Unknown panic")
}
}
}()
c.m.Lock()
defer c.m.Unlock()
if c.closed {
return
}
c.server.wg.Done()
c.closed = true
return c.Conn.Close()
}