From: qydysky Date: Sun, 30 Jul 2023 09:11:51 +0000 (+0800) Subject: add X-Git-Tag: v0.28.0+2023073001011e2 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=01011e2b019aaf1dab54a06c7d5539a2701e6501;p=part%2F.git add --- diff --git a/io/io.go b/io/io.go index 6382348..0285fe1 100644 --- 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 { diff --git a/reqf/Reqf.go b/reqf/Reqf.go index b4a9836..da11e22 100644 --- a/reqf/Reqf.go +++ b/reqf/Reqf.go @@ -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()