Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHo3ein <ho3ein.sanaei@gmail.com>2023-12-10 17:42:52 +0300
committerGitHub <noreply@github.com>2023-12-10 17:42:52 +0300
commite3f1d3c892a1af48f27fdc36f273a55f38d13b40 (patch)
treeb11d0c1ed3c15c8f6f891a5e6df8e021d5db8ab6 /xray/process.go
parent36cf7c0a8fda915b51e75958ce729fd9a61a5c90 (diff)
parent9fbe80f87f950673058f0001b3704251fa8b9243 (diff)
huge changes
Diffstat (limited to 'xray/process.go')
-rw-r--r--xray/process.go74
1 files changed, 16 insertions, 58 deletions
diff --git a/xray/process.go b/xray/process.go
index 2e545fba..9289362f 100644
--- a/xray/process.go
+++ b/xray/process.go
@@ -1,7 +1,6 @@
package xray
import (
- "bufio"
"bytes"
"encoding/json"
"errors"
@@ -10,16 +9,12 @@ import (
"os"
"os/exec"
"runtime"
- "strings"
- "sync"
"syscall"
"time"
"x-ui/config"
"x-ui/logger"
"x-ui/util/common"
-
- "github.com/Workiva/go-datastructures/queue"
)
func GetBinaryName() string {
@@ -98,8 +93,10 @@ type process struct {
version string
apiPort int
+ onlineClients []string
+
config *Config
- lines *queue.Queue
+ logWriter *LogWriter
exitErr error
startTime time.Time
}
@@ -108,7 +105,7 @@ func newProcess(config *Config) *process {
return &process{
version: "Unknown",
config: config,
- lines: queue.New(100),
+ logWriter: NewLogWriter(),
startTime: time.Now(),
}
}
@@ -128,17 +125,10 @@ func (p *process) GetErr() error {
}
func (p *process) GetResult() string {
- if p.lines.Empty() && p.exitErr != nil {
+ if len(p.logWriter.lastLine) == 0 && p.exitErr != nil {
return p.exitErr.Error()
}
- items, _ := p.lines.TakeUntil(func(item interface{}) bool {
- return true
- })
- lines := make([]string, 0, len(items))
- for _, item := range items {
- lines = append(lines, item.(string))
- }
- return strings.Join(lines, "\n")
+ return p.logWriter.lastLine
}
func (p *process) GetVersion() string {
@@ -153,6 +143,14 @@ func (p *Process) GetConfig() *Config {
return p.config
}
+func (p *Process) GetOnlineClients() []string {
+ return p.onlineClients
+}
+
+func (p *Process) SetOnlineClients(users []string) {
+ p.onlineClients = users
+}
+
func (p *Process) GetUptime() uint64 {
return uint64(time.Since(p.startTime).Seconds())
}
@@ -205,54 +203,14 @@ func (p *process) Start() (err error) {
cmd := exec.Command(GetBinaryPath(), "-c", configPath)
p.cmd = cmd
- stdReader, err := cmd.StdoutPipe()
- if err != nil {
- return err
- }
- errReader, err := cmd.StderrPipe()
- if err != nil {
- return err
- }
-
- var wg sync.WaitGroup
- wg.Add(2)
-
- go func() {
- defer wg.Done()
- reader := bufio.NewReaderSize(stdReader, 8192)
- for {
- line, _, err := reader.ReadLine()
- if err != nil {
- return
- }
- if p.lines.Len() >= 100 {
- p.lines.Get(1)
- }
- p.lines.Put(string(line))
- }
- }()
-
- go func() {
- defer wg.Done()
- reader := bufio.NewReaderSize(errReader, 8192)
- for {
- line, _, err := reader.ReadLine()
- if err != nil {
- return
- }
- if p.lines.Len() >= 100 {
- p.lines.Get(1)
- }
- p.lines.Put(string(line))
- }
- }()
+ cmd.Stdout = p.logWriter
+ cmd.Stderr = p.logWriter
go func() {
err := cmd.Run()
if err != nil {
p.exitErr = err
}
- wg.Wait()
}()
p.refreshVersion()