From: qydysky Date: Wed, 11 May 2022 02:03:54 +0000 (+0800) Subject: fix large allocs X-Git-Tag: v0.9.3~1 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=46eb80413c9bced474842231b0756ac57291a11b;p=part%2F.git fix large allocs --- diff --git a/io/io.go b/io/io.go index fb0be33..3499cd3 100644 --- a/io/io.go +++ b/io/io.go @@ -6,13 +6,13 @@ import ( //no close rc any time //you can close wc, r, w. -func RW2Chan(r io.ReadCloser,w io.WriteCloser) (rc,wc chan[]byte) { +func RW2Chan(r io.ReadCloser, w io.WriteCloser) (rc, wc chan []byte) { if r != nil { - rc = make(chan[]byte, 1<<16) - go func(rc chan[]byte,r io.ReadCloser){ + rc = make(chan []byte, 10) + go func(rc chan []byte, r io.ReadCloser) { for { buf := make([]byte, 1<<16) - n,e := r.Read(buf) + n, e := r.Read(buf) if n != 0 { rc <- buf[:n] } else if e != nil { @@ -20,25 +20,25 @@ func RW2Chan(r io.ReadCloser,w io.WriteCloser) (rc,wc chan[]byte) { break } } - }(rc,r) + }(rc, r) } - + if w != nil { - wc = make(chan[]byte, 1<<16) - go func(wc chan[]byte,w io.WriteCloser){ + wc = make(chan []byte, 10) + go func(wc chan []byte, w io.WriteCloser) { for { - buf :=<- wc - if len(buf) == 0 {//chan close + buf := <-wc + if len(buf) == 0 { //chan close w.Close() break } - _,e := w.Write(buf) + _, e := w.Write(buf) if e != nil { close(wc) break } } - }(wc,w) + }(wc, w) } return -} \ No newline at end of file +}