command_conntrack.go 535 B

12345678910111213141516171819202122232425262728
  1. package libbox
  2. import (
  3. "encoding/binary"
  4. "net"
  5. runtimeDebug "runtime/debug"
  6. "time"
  7. "github.com/sagernet/sing-box/common/conntrack"
  8. )
  9. func (c *CommandClient) CloseConnections() error {
  10. conn, err := c.directConnect()
  11. if err != nil {
  12. return err
  13. }
  14. defer conn.Close()
  15. return binary.Write(conn, binary.BigEndian, uint8(CommandCloseConnections))
  16. }
  17. func (s *CommandServer) handleCloseConnections(conn net.Conn) error {
  18. conntrack.Close()
  19. go func() {
  20. time.Sleep(time.Second)
  21. runtimeDebug.FreeOSMemory()
  22. }()
  23. return nil
  24. }