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
61885aa9
Commit
61885aa9
authored
Apr 19, 2015
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't export types/functions
parent
2c229bac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
+16
-16
http.go
rpc/http.go
+4
-4
types.go
rpc/types.go
+12
-12
No files found.
rpc/http.go
View file @
61885aa9
...
...
@@ -14,7 +14,7 @@ import (
)
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
var
rpclistener
*
S
toppableTCPListener
var
rpclistener
*
s
toppableTCPListener
const
(
jsonrpcver
=
"2.0"
...
...
@@ -29,7 +29,7 @@ func Start(pipe *xeth.XEth, config RpcConfig) error {
return
nil
// RPC service already running on given host/port
}
l
,
err
:=
N
ewStoppableTCPListener
(
fmt
.
Sprintf
(
"%s:%d"
,
config
.
ListenAddress
,
config
.
ListenPort
))
l
,
err
:=
n
ewStoppableTCPListener
(
fmt
.
Sprintf
(
"%s:%d"
,
config
.
ListenAddress
,
config
.
ListenPort
))
if
err
!=
nil
{
rpclogger
.
Errorf
(
"Can't listen on %s:%d: %v"
,
config
.
ListenAddress
,
config
.
ListenPort
,
err
)
return
err
...
...
@@ -43,9 +43,9 @@ func Start(pipe *xeth.XEth, config RpcConfig) error {
opts
.
AllowedOrigins
=
[]
string
{
config
.
CorsDomain
}
c
:=
cors
.
New
(
opts
)
handler
=
N
ewStoppableHandler
(
c
.
Handler
(
JSONRPC
(
pipe
)),
l
.
stop
)
handler
=
n
ewStoppableHandler
(
c
.
Handler
(
JSONRPC
(
pipe
)),
l
.
stop
)
}
else
{
handler
=
N
ewStoppableHandler
(
JSONRPC
(
pipe
),
l
.
stop
)
handler
=
n
ewStoppableHandler
(
JSONRPC
(
pipe
),
l
.
stop
)
}
go
http
.
Serve
(
l
,
handler
)
...
...
rpc/types.go
View file @
61885aa9
...
...
@@ -265,18 +265,18 @@ type RpcErrorObject struct {
// Data interface{} `json:"data"`
}
type
Listener
StoppedError
struct
{
type
listenerHas
StoppedError
struct
{
msg
string
}
func
(
self
Listener
StoppedError
)
Error
()
string
{
func
(
self
listenerHas
StoppedError
)
Error
()
string
{
return
self
.
msg
}
var
listenerStoppedError
=
Listener
StoppedError
{
"Listener stopped"
}
var
listenerStoppedError
=
listenerHas
StoppedError
{
"Listener stopped"
}
// When https://github.com/golang/go/issues/4674 is fixed this could be replaced
type
S
toppableTCPListener
struct
{
type
s
toppableTCPListener
struct
{
*
net
.
TCPListener
stop
chan
struct
{}
// closed when the listener must stop
}
...
...
@@ -284,7 +284,7 @@ type StoppableTCPListener struct {
// 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
N
ewStoppableHandler
(
h
http
.
Handler
,
stop
chan
struct
{})
http
.
Handler
{
func
n
ewStoppableHandler
(
h
http
.
Handler
,
stop
chan
struct
{})
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
select
{
case
<-
stop
:
...
...
@@ -298,11 +298,11 @@ func NewStoppableHandler(h http.Handler, stop chan struct{}) http.Handler {
}
// Stop the listener and all accepted and still active connections.
func
(
self
*
S
toppableTCPListener
)
Stop
()
{
func
(
self
*
s
toppableTCPListener
)
Stop
()
{
close
(
self
.
stop
)
}
func
NewStoppableTCPListener
(
addr
string
)
(
*
S
toppableTCPListener
,
error
)
{
func
newStoppableTCPListener
(
addr
string
)
(
*
s
toppableTCPListener
,
error
)
{
wl
,
err
:=
net
.
Listen
(
"tcp"
,
addr
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -310,14 +310,14 @@ func NewStoppableTCPListener(addr string) (*StoppableTCPListener, error) {
if
tcpl
,
ok
:=
wl
.
(
*
net
.
TCPListener
);
ok
{
stop
:=
make
(
chan
struct
{})
l
:=
&
S
toppableTCPListener
{
tcpl
,
stop
}
l
:=
&
s
toppableTCPListener
{
tcpl
,
stop
}
return
l
,
nil
}
return
nil
,
errors
.
New
(
"Unable to create TCP listener for RPC service"
)
}
func
(
self
*
S
toppableTCPListener
)
Accept
()
(
net
.
Conn
,
error
)
{
func
(
self
*
s
toppableTCPListener
)
Accept
()
(
net
.
Conn
,
error
)
{
for
{
self
.
SetDeadline
(
time
.
Now
()
.
Add
(
time
.
Duration
(
1
*
time
.
Second
)))
c
,
err
:=
self
.
TCPListener
.
AcceptTCP
()
...
...
@@ -338,16 +338,16 @@ func (self *StoppableTCPListener) Accept() (net.Conn, error) {
}
}
return
&
C
losableConnection
{
c
,
self
.
stop
},
err
return
&
c
losableConnection
{
c
,
self
.
stop
},
err
}
}
type
C
losableConnection
struct
{
type
c
losableConnection
struct
{
*
net
.
TCPConn
closed
chan
struct
{}
}
func
(
self
*
C
losableConnection
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
func
(
self
*
c
losableConnection
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
select
{
case
<-
self
.
closed
:
self
.
TCPConn
.
Close
()
...
...
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