Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
f589728f
Commit
f589728f
authored
Apr 22, 2011
by
Petar Maymounkov
Committed by
Russ Cox
Apr 22, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: in ServerConn and ClientConn, rename Close to Hijack, add Close
R=rsc CC=golang-dev
https://golang.org/cl/4372046
parent
361e4e5f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
13 deletions
+31
-13
src/pkg/http/persist.go
src/pkg/http/persist.go
+31
-13
No files found.
src/pkg/http/persist.go
View file @
f589728f
...
...
@@ -20,8 +20,8 @@ var (
// A ServerConn reads requests and sends responses over an underlying
// connection, until the HTTP keepalive logic commands an end. ServerConn
//
does not close the underlying connection. Instead, the user calls Close
//
and regains
control over the connection. ServerConn supports pipe-lining,
//
also allows hijacking the underlying connection by calling Hijack
//
to regain
control over the connection. ServerConn supports pipe-lining,
// i.e. requests can be read out of sync (but in the same order) while the
// respective responses are sent.
type
ServerConn
struct
{
...
...
@@ -45,11 +45,11 @@ func NewServerConn(c net.Conn, r *bufio.Reader) *ServerConn {
return
&
ServerConn
{
c
:
c
,
r
:
r
,
pipereq
:
make
(
map
[
*
Request
]
uint
)}
}
//
Close
detaches the ServerConn and returns the underlying connection as well
// as the read-side bufio which may have some left over data.
Close
may be
//
Hijack
detaches the ServerConn and returns the underlying connection as well
// as the read-side bufio which may have some left over data.
Hijack
may be
// called before Read has signaled the end of the keep-alive logic. The user
// should not call
Close
while Read or Write is in progress.
func
(
sc
*
ServerConn
)
Close
()
(
c
net
.
Conn
,
r
*
bufio
.
Reader
)
{
// should not call
Hijack
while Read or Write is in progress.
func
(
sc
*
ServerConn
)
Hijack
()
(
c
net
.
Conn
,
r
*
bufio
.
Reader
)
{
sc
.
lk
.
Lock
()
defer
sc
.
lk
.
Unlock
()
c
=
sc
.
c
...
...
@@ -59,6 +59,15 @@ func (sc *ServerConn) Close() (c net.Conn, r *bufio.Reader) {
return
}
// Close calls Hijack and then also closes the underlying connection
func
(
sc
*
ServerConn
)
Close
()
os
.
Error
{
c
,
_
:=
sc
.
Hijack
()
if
c
!=
nil
{
return
c
.
Close
()
}
return
nil
}
// Read returns the next request on the wire. An ErrPersistEOF is returned if
// it is gracefully determined that there are no more requests (e.g. after the
// first request on an HTTP/1.0 connection, or after a Connection:close on a
...
...
@@ -199,9 +208,9 @@ func (sc *ServerConn) Write(req *Request, resp *Response) os.Error {
}
// A ClientConn sends request and receives headers over an underlying
// connection, while respecting the HTTP keepalive logic. ClientConn
is not
//
responsible for closing the underlying connection. One must call Close
to
// regain control of th
at connectio
n and deal with it as desired.
// connection, while respecting the HTTP keepalive logic. ClientConn
//
supports hijacking the connection calling Hijack
to
// regain control of th
e underlying net.Con
n and deal with it as desired.
type
ClientConn
struct
{
lk
sync
.
Mutex
// read-write protects the following fields
c
net
.
Conn
...
...
@@ -239,11 +248,11 @@ func NewProxyClientConn(c net.Conn, r *bufio.Reader) *ClientConn {
return
cc
}
//
Close
detaches the ClientConn and returns the underlying connection as well
// as the read-side bufio which may have some left over data.
Close
may be
//
Hijack
detaches the ClientConn and returns the underlying connection as well
// as the read-side bufio which may have some left over data.
Hijack
may be
// called before the user or Read have signaled the end of the keep-alive
// logic. The user should not call
Close
while Read or Write is in progress.
func
(
cc
*
ClientConn
)
Close
()
(
c
net
.
Conn
,
r
*
bufio
.
Reader
)
{
// logic. The user should not call
Hijack
while Read or Write is in progress.
func
(
cc
*
ClientConn
)
Hijack
()
(
c
net
.
Conn
,
r
*
bufio
.
Reader
)
{
cc
.
lk
.
Lock
()
defer
cc
.
lk
.
Unlock
()
c
=
cc
.
c
...
...
@@ -253,6 +262,15 @@ func (cc *ClientConn) Close() (c net.Conn, r *bufio.Reader) {
return
}
// Close calls Hijack and then also closes the underlying connection
func
(
cc
*
ClientConn
)
Close
()
os
.
Error
{
c
,
_
:=
cc
.
Hijack
()
if
c
!=
nil
{
return
c
.
Close
()
}
return
nil
}
// Write writes a request. An ErrPersistEOF error is returned if the connection
// has been closed in an HTTP keepalive sense. If req.Close equals true, the
// keepalive connection is logically closed after this request and the opposing
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment