Skip to content

Commit

Permalink
neat(x/net/http/client): Go fmt style
Browse files Browse the repository at this point in the history
  • Loading branch information
spongehah committed Sep 20, 2024
1 parent 0382274 commit 1fb70ad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 173 deletions.
2 changes: 1 addition & 1 deletion x/net/http/_demo/parallelRequest/parallelRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func worker(id int, wg *sync.WaitGroup) {

func main() {
var wait sync.WaitGroup
for i := 0; i < 500; i++ {
for i := 0; i < 100; i++ {
wait.Add(1)
go worker(i, &wait)
}
Expand Down
11 changes: 3 additions & 8 deletions x/net/http/body_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package http

import (
"errors"
"fmt"

"github.com/goplus/llgo/c/libuv"
)
Expand All @@ -18,7 +17,7 @@ type bodyStream struct {
}

var (
ErrClosedRequestBody = errors.New("request body: read/write on closed body")
ErrClosedBodyStream = errors.New("body stream: read/write on closed body")
)

func newBodyStream(asyncHandle *libuv.Async) *bodyStream {
Expand All @@ -30,7 +29,6 @@ func newBodyStream(asyncHandle *libuv.Async) *bodyStream {
}

func (rb *bodyStream) Read(p []byte) (n int, err error) {
fmt.Println("[debug] RequestBody Read called")
select {
case <-rb.done:
err = rb.readCloseError()
Expand All @@ -41,11 +39,9 @@ func (rb *bodyStream) Read(p []byte) (n int, err error) {
for n < len(p) {
if len(rb.chunk) == 0 {
rb.asyncHandle.Send()
fmt.Println("[debug] RequestBody Read asyncHandle.Send called")
select {
case chunk := <-rb.readCh:
rb.chunk = chunk
fmt.Println("[debug] RequestBody Read chunk received")
case <-rb.done:
err = rb.readCloseError()
return
Expand All @@ -64,16 +60,15 @@ func (rb *bodyStream) readCloseError() error {
if rerr := rb.rerr; rerr != nil {
return rerr
}
return ErrClosedRequestBody
return ErrClosedBodyStream
}

func (rb *bodyStream) closeWithError(err error) error {
fmt.Println("[debug] RequestBody closeRead called")
if rb.rerr != nil {
return nil
}
if err == nil {
err = ErrClosedRequestBody
err = ErrClosedBodyStream
}
rb.rerr = err
close(rb.done)
Expand Down
6 changes: 0 additions & 6 deletions x/net/http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,12 @@ func (r *Response) checkRespBody(taskData *clientTaskData) (needContinue bool) {
select {
case taskData.resc <- responseAndError{res: r}:
case <-taskData.callerGone:
if debugSwitch {
println("############### checkRespBody callerGone")
}
closeAndRemoveIdleConn(pc, true)
return true
}
// Now that they've read from the unbuffered channel, they're safely
// out of the select that also waits on this goroutine to die, so
// we're allowed to exit now if needed (if alive is false)
if debugSwitch {
println("############### checkRespBody return")
}
closeAndRemoveIdleConn(pc, false)
return true
}
Expand Down
Loading

0 comments on commit 1fb70ad

Please sign in to comment.