command_conntrack.go 583 B

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