From: qydysky Date: Wed, 12 Aug 2020 17:02:07 +0000 (+0800) Subject: 44 X-Git-Tag: v0.0.2~43 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=0eeb950bc4be35d4253a67b61baa801bbca073af;p=part%2F.git 44 --- diff --git a/Log.go b/Log.go index ab2f0a4..67c95e6 100644 --- a/Log.go +++ b/Log.go @@ -12,7 +12,6 @@ type logl struct { channelN chan int channel chan interface{} wantLog chan bool - waitclose chan bool tracef *log.Logger // 记录所有日志 infof *log.Logger // 重要的信息 warningf *log.Logger // 需要注意的信息 @@ -25,7 +24,6 @@ func Logf() (*logl) { func (l *logl) New(fileP string) { l.wantLog = make(chan bool,2) - l.waitclose = make(chan bool) l.channelN = make(chan int,200) l.channel = make(chan interface{},200) @@ -52,6 +50,7 @@ func (l *logl) New(fileP string) { log.Println("ERROR:",<- l.channel) } } + for len(l.wantLog) != 0 {<- l.wantLog} continue } @@ -60,6 +59,7 @@ func (l *logl) New(fileP string) { os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { l.E("Failed to open log file:", err) + for len(l.wantLog) != 0 {<- l.wantLog} continue } @@ -67,6 +67,7 @@ func (l *logl) New(fileP string) { if err != nil { l.E("cannot flock", fileName, err) file.Close() + for len(l.wantLog) != 0 {<- l.wantLog} continue } @@ -90,8 +91,7 @@ func (l *logl) New(fileP string) { i := <- l.channelN switch i { case -1: - l.fileName = "" - l.waitclose <- true + l.Close() case 0: l.tracef.Println(<- l.channel) case 1: @@ -110,7 +110,7 @@ func (l *logl) New(fileP string) { file.Close() - <- l.wantLog + for len(l.wantLog) != 0 {<- l.wantLog} } }() } @@ -120,9 +120,9 @@ func (l *logl) Close(){ } func (l *logl) WClose(){ + if l.fileName == "" {return} l.channelN <- -1 - if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true} - <- l.waitclose + if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true;} } func (l *logl) T(i ...interface{}){ diff --git a/Net.go b/Net.go index f6f3aa3..df0968f 100644 --- a/Net.go +++ b/Net.go @@ -7,6 +7,7 @@ import ( "bytes" "os/exec" "runtime" + "time" "github.com/miekg/dns" ) @@ -142,14 +143,20 @@ func (t *netl) Forward(targetaddr,targetnetwork *string, Need_Accept bool) { break } - targetconn, err := net.Dial(*targetnetwork, *targetaddr) - if err != nil { - Logf().E("[part/Forward]Unable to connect:", *targetaddr, err.Error()) - proxyconn.Close() - continue + retry := 0 + for { + targetconn, err := net.Dial(*targetnetwork, *targetaddr) + if err != nil { + Logf().E("[part/Forward]Unable to connect:", *targetaddr, err.Error()) + retry += 1 + if retry >= 2 {proxyconn.Close();break} + time.Sleep(time.Duration(1)*time.Millisecond) + continue + } + + go tcpBridge2(proxyconn,targetconn) + break } - - go tcpBridge2(proxyconn,targetconn) } }