Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2c229bac
Commit
2c229bac
authored
Apr 19, 2015
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced channel pointer field with non pointer channel
parent
ead3dd97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
11 deletions
+14
-11
http.go
rpc/http.go
+1
-1
types.go
rpc/types.go
+13
-10
No files found.
rpc/http.go
View file @
2c229bac
...
...
@@ -45,7 +45,7 @@ func Start(pipe *xeth.XEth, config RpcConfig) error {
c
:=
cors
.
New
(
opts
)
handler
=
NewStoppableHandler
(
c
.
Handler
(
JSONRPC
(
pipe
)),
l
.
stop
)
}
else
{
handler
=
JSONRPC
(
pipe
)
handler
=
NewStoppableHandler
(
JSONRPC
(
pipe
),
l
.
stop
)
}
go
http
.
Serve
(
l
,
handler
)
...
...
rpc/types.go
View file @
2c229bac
...
...
@@ -275,20 +275,21 @@ func (self ListenerStoppedError) Error() string {
var
listenerStoppedError
=
ListenerStoppedError
{
"Listener stopped"
}
// When https://github.com/golang/go/issues/4674 is fixed this could be replaced
type
StoppableTCPListener
struct
{
*
net
.
TCPListener
stop
*
chan
struct
{}
// closed when the listener must stop
stop
chan
struct
{}
// closed when the listener must stop
}
// Wraps the default handler and checks if the RPC service was stopped. In that case it returns an
// error indicating that the service was stopped. This will only happen for connections which are
// kept open (HTTP keep-alive) when the RPC service was shutdown.
func
NewStoppableHandler
(
h
http
.
Handler
,
stop
*
chan
struct
{})
http
.
Handler
{
func
NewStoppableHandler
(
h
http
.
Handler
,
stop
chan
struct
{})
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
select
{
case
<-
*
stop
:
case
<-
stop
:
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
jsonerr
:=
&
RpcErrorObject
{
-
32603
,
"RPC service stop
t
"
}
jsonerr
:=
&
RpcErrorObject
{
-
32603
,
"RPC service stop
ped
"
}
send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
default
:
h
.
ServeHTTP
(
w
,
r
)
...
...
@@ -298,7 +299,7 @@ func NewStoppableHandler(h http.Handler, stop *chan struct{}) http.Handler {
// Stop the listener and all accepted and still active connections.
func
(
self
*
StoppableTCPListener
)
Stop
()
{
close
(
*
self
.
stop
)
close
(
self
.
stop
)
}
func
NewStoppableTCPListener
(
addr
string
)
(
*
StoppableTCPListener
,
error
)
{
...
...
@@ -309,7 +310,7 @@ func NewStoppableTCPListener(addr string) (*StoppableTCPListener, error) {
if
tcpl
,
ok
:=
wl
.
(
*
net
.
TCPListener
);
ok
{
stop
:=
make
(
chan
struct
{})
l
:=
&
StoppableTCPListener
{
tcpl
,
&
stop
}
l
:=
&
StoppableTCPListener
{
tcpl
,
stop
}
return
l
,
nil
}
...
...
@@ -322,8 +323,10 @@ func (self *StoppableTCPListener) Accept() (net.Conn, error) {
c
,
err
:=
self
.
TCPListener
.
AcceptTCP
()
select
{
case
<-*
self
.
stop
:
c
.
Close
()
case
<-
self
.
stop
:
if
c
!=
nil
{
// accept timeout
c
.
Close
()
}
self
.
TCPListener
.
Close
()
return
nil
,
listenerStoppedError
default
:
...
...
@@ -341,12 +344,12 @@ func (self *StoppableTCPListener) Accept() (net.Conn, error) {
type
ClosableConnection
struct
{
*
net
.
TCPConn
closed
*
chan
struct
{}
closed
chan
struct
{}
}
func
(
self
*
ClosableConnection
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
select
{
case
<-
*
self
.
closed
:
case
<-
self
.
closed
:
self
.
TCPConn
.
Close
()
return
0
,
io
.
EOF
default
:
...
...
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