platform: Fixes and improvements

This commit is contained in:
世界 2023-04-05 04:38:56 +08:00
parent 28aa4c4d1f
commit 8b64446274
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
16 changed files with 33 additions and 31 deletions

View File

@ -14,10 +14,16 @@ var (
)
func Count() int {
if !Enabled {
return 0
}
return openConnection.Len()
}
func List() []io.Closer {
if !Enabled {
return nil
}
connAccess.RLock()
defer connAccess.RUnlock()
connList := make([]io.Closer, 0, openConnection.Len())
@ -28,6 +34,9 @@ func List() []io.Closer {
}
func Close() {
if !Enabled {
return
}
connAccess.Lock()
defer connAccess.Unlock()
for element := openConnection.Front(); element != nil; element = element.Next() {

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
const (

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (
@ -46,6 +44,7 @@ func clientConnect(sharedDirectory string) (net.Conn, error) {
}
func (c *CommandClient) Connect() error {
common.Close(c.conn)
conn, err := clientConnect(c.sharedDirectory)
if err != nil {
return err

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (
@ -10,6 +8,7 @@ import (
"sync"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/observable"
"github.com/sagernet/sing/common/x/list"
@ -57,7 +56,10 @@ func (s *CommandServer) Start() error {
}
func (s *CommandServer) Close() error {
return s.listener.Close()
return common.Close(
s.listener,
s.observer,
)
}
func (s *CommandServer) loopConnection(listener net.Listener) {

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build darwin
package libbox
import (

View File

@ -1,9 +1,9 @@
//go:build linux || darwin
package libbox
import (
"bytes"
"context"
"encoding/json"
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/option"
@ -35,3 +35,19 @@ func CheckConfig(configContent string) error {
}
return err
}
func FormatConfig(configContent string) (string, error) {
options, err := parseConfig(configContent)
if err != nil {
return "", err
}
var buffer bytes.Buffer
json.NewEncoder(&buffer)
encoder := json.NewEncoder(&buffer)
encoder.SetIndent("", " ")
err = encoder.Encode(options)
if err != nil {
return "", err
}
return buffer.String(), nil
}

View File

@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import "github.com/sagernet/sing/common"

View File

@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import "github.com/sagernet/sing-box/option"

View File

@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (

View File

@ -1,5 +1,3 @@
//go:build linux || darwin
package libbox
import (