1
0

conn.go 388 B

12345678910111213141516171819202122232425262728
  1. package grace
  2. import (
  3. "errors"
  4. "net"
  5. )
  6. type graceConn struct {
  7. net.Conn
  8. server *Server
  9. }
  10. func (c graceConn) Close() (err error) {
  11. defer func() {
  12. if r := recover(); r != nil {
  13. switch x := r.(type) {
  14. case string:
  15. err = errors.New(x)
  16. case error:
  17. err = x
  18. default:
  19. err = errors.New("Unknown panic")
  20. }
  21. }
  22. }()
  23. c.server.wg.Done()
  24. return c.Conn.Close()
  25. }