]> 127.0.0.1 Git - part/.git/commitdiff
add v0.28.0+2023073001011e2
authorqydysky <qydysky@foxmail.com>
Sun, 30 Jul 2023 09:11:51 +0000 (17:11 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 30 Jul 2023 09:11:51 +0000 (17:11 +0800)
io/io.go
reqf/Reqf.go

index 6382348e11e974a891c56625ab1c4489110fb738..0285fe127f8c59cd0c71bf5ee522f454d184031b 100644 (file)
--- a/io/io.go
+++ b/io/io.go
@@ -223,7 +223,7 @@ var (
 //
 // call Close() after writer fin
 func WithCtxCopy(ctx context.Context, callTree string, to time.Duration, w []io.Writer, r io.Reader, panicf ...func(s string)) error {
-       rwc := WithCtxTO(ctx, callTree, to, w, r)
+       rwc := WithCtxTO(ctx, callTree, to, w, r, panicf...)
        defer rwc.Close()
        for buf := make([]byte, 2048); true; {
                if n, e := rwc.Read(buf); n != 0 {
index b4a98364fa5deb3c227e524597194a70542137b6..da11e225f9e1ace783c22c18a6b55b5c8d360efe 100644 (file)
@@ -26,12 +26,15 @@ import (
 )
 
 type Rval struct {
-       Url              string
-       PostStr          string
-       Timeout          int
-       Proxy            string
-       Retry            int
-       SleepTime        int
+       Url     string
+       PostStr string
+       Proxy   string
+       Retry   int
+       // Millisecond
+       Timeout int
+       // Millisecond
+       SleepTime int
+       // Millisecond
        WriteLoopTO      int
        JustResponseCode bool
        NoResponse       bool
@@ -259,11 +262,18 @@ func (t *Req) Reqf_1(ctx context.Context, val Rval) (err error) {
 
        writeLoopTO := val.WriteLoopTO
        if writeLoopTO == 0 {
-               writeLoopTO = 1000
+               if val.Timeout > 0 {
+                       writeLoopTO = val.Timeout + 500
+               } else {
+                       writeLoopTO = 1000
+               }
        }
 
        // io copy
-       err = errors.Join(err, pio.WithCtxCopy(req.Context(), t.callTree, time.Duration(int(time.Millisecond)*writeLoopTO), ws, resReadCloser))
+       var panicf = func(s string) {
+               err = errors.Join(err, errors.New(s))
+       }
+       err = errors.Join(err, pio.WithCtxCopy(req.Context(), t.callTree, time.Duration(int(time.Millisecond)*writeLoopTO), ws, resReadCloser, panicf))
 
        resp.Body.Close()