This commit is contained in:
世界 2023-03-15 14:56:06 +08:00
parent 78e02b52ca
commit 5a4e8fea81
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
10 changed files with 15 additions and 76 deletions

View file

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

View file

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

View file

@ -1,54 +0,0 @@
package libbox
import (
"bufio"
"log"
"os"
)
type StandardOutput interface {
WriteOutput(message string)
WriteErrorOutput(message string)
}
func SetOutput(output StandardOutput) {
log.SetOutput(logWriter{output})
pipeIn, pipeOut, err := os.Pipe()
if err != nil {
panic(err)
}
os.Stdout = os.NewFile(pipeOut.Fd(), "stdout")
go lineLog(pipeIn, output.WriteOutput)
pipeIn, pipeOut, err = os.Pipe()
if err != nil {
panic(err)
}
os.Stderr = os.NewFile(pipeOut.Fd(), "srderr")
go lineLog(pipeIn, output.WriteErrorOutput)
}
type logWriter struct {
output StandardOutput
}
func (w logWriter) Write(p []byte) (n int, err error) {
w.output.WriteOutput(string(p))
return len(p), nil
}
func lineLog(f *os.File, output func(string)) {
const logSize = 1024 // matches android/log.h.
r := bufio.NewReaderSize(f, logSize)
for {
line, _, err := r.ReadLine()
str := string(line)
if err != nil {
str += " " + err.Error()
}
output(str)
if err != nil {
break
}
}
}

View file

@ -1,3 +1,5 @@
//go:build darwin
package libbox package libbox
import "runtime/debug" import "runtime/debug"

View file

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

View file

@ -1,4 +1,4 @@
//go:build debug //go:build linux || darwin
package libbox package libbox

View file

@ -1,21 +0,0 @@
//go:build !debug
package libbox
import (
"os"
)
type PProfServer struct{}
func NewPProfServer(port int) *PProfServer {
return &PProfServer{}
}
func (s *PProfServer) Start() error {
return os.ErrInvalid
}
func (s *PProfServer) Close() error {
return os.ErrInvalid
}

View file

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

View file

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

View file

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