Source File
persist.go
Belonging Package
net/http/httputil
package httputil
import (
)
ErrPersistEOF = &http.ProtocolError{ErrorString: "persistent connection closed"}
ErrClosed = &http.ProtocolError{ErrorString: "connection closed by user"}
ErrPipeline = &http.ProtocolError{ErrorString: "pipeline error"}
)
:= .pipe.Next()
.pipe.StartRequest()
defer func() {
.pipe.EndRequest()
if == nil {
.pipe.StartResponse()
.pipe.EndResponse()
.mu.Lock()
.pipereq[] =
.mu.Unlock()
}
}()
.mu.Lock()
if .we != nil { // no point receiving if write-side broken or closed
defer .mu.Unlock()
return nil, .we
}
if .re != nil {
defer .mu.Unlock()
return nil, .re
}
if .r == nil { // connection closed by user in the meantime
defer .mu.Unlock()
return nil, errClosed
}
:= .r
:= .lastbody
.lastbody = nil
.mu.Unlock()
.pipe.StartResponse()
defer .pipe.EndResponse()
.mu.Lock()
if .we != nil {
defer .mu.Unlock()
return .we
}
if .c == nil { // connection closed by user in the meantime
defer .mu.Unlock()
return ErrClosed
}
:= .c
if .nread <= .nwritten {
defer .mu.Unlock()
return errors.New("persist server pipe count")
}
func ( net.Conn, *bufio.Reader) *ClientConn {
:= NewClientConn(, )
.writeReq = (*http.Request).WriteProxy
return
}
func ( *ClientConn) ( *http.Request) error {
var error
:= .pipe.Next()
.pipe.StartRequest()
defer func() {
.pipe.EndRequest()
if != nil {
.pipe.StartResponse()
.pipe.EndResponse()
.mu.Lock()
.pipereq[] =
.mu.Unlock()
}
}()
.mu.Lock()
if .re != nil { // no point sending if read-side closed or broken
defer .mu.Unlock()
return .re
}
if .we != nil {
defer .mu.Unlock()
return .we
}
if .c == nil { // connection closed by user in the meantime
defer .mu.Unlock()
return errClosed
}
:= .c
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |