var n int
n, err = io.ReadFull(wr.request.Body, buf)
ws.peer.readBytes(int64(n))
+ reqCtxErr := context.Cause(wr.request.Context())
+ if errors.Is(err, reqCtxErr) {
+ err = reqCtxErr
+ }
if webseed.PrintDebug && wr.cancelled.Load() {
fmt.Printf("webseed read %v after cancellation: %v\n", n, err)
}
}
type Request struct {
+ // So you can view it from externally.
+ ctx context.Context
cancel context.CancelCauseFunc
Body io.Reader
// Closed with error to unstick copy routine when context isn't checked.
bodyPipe *io.PipeReader
}
-func (r Request) Cancel(cause error) {
+func (r *Request) Context() context.Context {
+ return r.ctx
+}
+
+func (r *Request) Cancel(cause error) {
r.cancel(cause)
}
-func (r Request) Close() {
+func (r *Request) Close() {
// We aren't cancelling because we want to know if we can keep receiving buffered data after
// cancellation. PipeReader.Close always returns nil.
_ = r.bodyPipe.Close()
panicif.Zero(len(requestParts))
body, w := io.Pipe()
req := Request{
+ ctx: ctx,
cancel: cancel,
Body: body,
bodyPipe: body,