]> 127.0.0.1 Git - part/.git/commitdiff
98 log reqf bug 修复
authorqydysky <qydysky@foxmail.com>
Wed, 6 Jan 2021 13:34:14 +0000 (21:34 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 6 Jan 2021 13:34:14 +0000 (21:34 +0800)
Reqf.go
log/Log.go
msgq/Msgq_test.go

diff --git a/Reqf.go b/Reqf.go
index 08b1485f19da679b04aea7f81f60f8997986c5e3..1990258a730a1350e4911b7a0b6bc6695db835fc 100644 (file)
--- a/Reqf.go
+++ b/Reqf.go
@@ -122,11 +122,15 @@ func (this *req) Reqf_1(val Rval) (error) {
     req,_ := http.NewRequest(Method, Url, body)
     req = req.WithContext(cx)
 
+    var done = make(chan struct{})
+    defer close(done)
     go func(){
         this.cancel = make(chan interface{})
         this.cancelOpen = true
-        <- this.cancel
-        cancel()
+        select {
+        case <- this.cancel:cancel()
+        case <- done:
+        }
     }()
     
     if _,ok := Header["Accept"];!ok {Header["Accept"] = `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8`}
index d81a2290894fcadd958d05d5f74a9a93b963b3e9..e52ce9599618ea713c10b031a00a0c7e30ae26f3 100644 (file)
@@ -30,6 +30,7 @@ type Config struct {
 type Msg_item struct {
     Prefix string
     Msg_obj []interface{}
+    Config
 }
 
 //New 初始化
@@ -42,25 +43,26 @@ func New(c Config) (o *Log_interface) {
     
     if c.File != `` {p.File().NewPath(c.File)}
 
-    o.MQ = m.New(10)
+    o.MQ = m.New(100)
     o.MQ.Pull_tag(map[string]func(interface{})(bool){
         `block`:func(data interface{})(bool){
             if v,ok := data.(*s.Signal);ok{v.Done()}
             return false
         },
         `L`:func(data interface{})(bool){
+            msg := data.(Msg_item)
             var showObj = []io.Writer{}
-            if o.Stdout {showObj = append(showObj, os.Stdout)} 
-            if o.File != `` {
-                file, err := os.OpenFile(o.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
+            if msg.Stdout {showObj = append(showObj, os.Stdout)} 
+            if msg.File != `` {
+                file, err := os.OpenFile(msg.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
                 if err == nil {
                     showObj = append(showObj, file)
                     defer file.Close()
                 }else{log.Println(err)}
             }
             log.New(io.MultiWriter(showObj...),
-            data.(Msg_item).Prefix,
-            log.Ldate|log.Ltime).Println(data.(Msg_item).Msg_obj...)
+            msg.Prefix,
+            log.Ldate|log.Ltime).Println(msg.Msg_obj...)
             return false
         },
     })
@@ -76,7 +78,17 @@ func New(c Config) (o *Log_interface) {
 
 //
 func Copy(i *Log_interface)(o *Log_interface){
-    o = New((*i).Config)
+    o = new(Log_interface)
+    //设置
+    o.Config = (*i).Config
+    o.MQ = (*i).MQ
+    {//启动阻塞
+        b := s.Init()
+        for b.Islive() {
+            o.MQ.Push_tag(`block`,b)
+            time.Sleep(time.Duration(20)*time.Millisecond)
+        }
+    }
     return
 }
 
@@ -91,7 +103,7 @@ func (I *Log_interface) Level(log map[string]struct{}) (O *Log_interface) {
 
 //Open 日志不显示
 func (I *Log_interface) Log_show_control(show bool) (O *Log_interface) {
-    O=I
+    O = Copy(I)
     //
     O.Block(100)
     O.Stdout = show
@@ -136,6 +148,7 @@ func (I *Log_interface) L(prefix string, i ...interface{}) (O *Log_interface) {
     O.MQ.Push_tag(`L`,Msg_item{
         Prefix:prefix,
         Msg_obj:append(O.Base_string, i),
+        Config:O.Config,
     })
     return
 }
\ No newline at end of file
index 98157e1ab8cd7063d693e5f7be7c48aedc8a6ac4..a226f7edb1596084900cfe31e655547f3a8fd4f6 100644 (file)
@@ -3,6 +3,8 @@ package part
 import (
        "time"
        "fmt"
+       "net/http"
+       _ "net/http/pprof"
        "testing"
        p "github.com/qydysky/part"
 )
@@ -234,3 +236,34 @@ func Test_msgq5(t *testing.T) {
        }
        t.Log(`fin`)
 }
+
+func Test_msgq6(t *testing.T) {
+       mq := New(30)
+       go func() {
+               http.ListenAndServe("0.0.0.0:8899", nil)
+       }()
+       go mq.Pull_tag(map[string]func(interface{})(bool){
+               `A1`:func(data interface{})(bool){
+                       return false
+               },
+               `A2`:func(data interface{})(bool){
+                       if v,ok := data.(string);!ok || v != `a11`{t.Error(`2`)}
+                       return false
+               },
+               `Error`:func(data interface{})(bool){
+                       if data == nil {t.Error(`out of list`)}
+                       return false
+               },
+       })
+       
+       var fin_turn = 0
+       t.Log(`start`)
+       for fin_turn < 1000 {
+               time.Sleep(time.Second)
+               time.Sleep(time.Second)
+               mq.Push_tag(`A1`,`a11`)
+               fin_turn+=1
+               fmt.Print("\r",fin_turn)
+       }
+       t.Log(`fin`)
+}