good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
61885aa9
Commit
61885aa9
authored
Apr 19, 2015
by
Bas van Kervel
Browse files
Options
Downloads
Patches
Plain Diff
Don't export types/functions
parent
2c229bac
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rpc/http.go
+4
-4
4 additions, 4 deletions
rpc/http.go
rpc/types.go
+12
-12
12 additions, 12 deletions
rpc/types.go
with
16 additions
and
16 deletions
rpc/http.go
+
4
−
4
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
)
...
...
This diff is collapsed.
Click to expand it.
rpc/types.go
+
12
−
12
View file @
61885aa9
...
...
@@ -265,18 +265,18 @@ type RpcErrorObject struct {
// Data interface{} `json:"data"`
}
type
L
istenerStoppedError
struct
{
type
l
istener
Has
StoppedError
struct
{
msg
string
}
func
(
self
L
istenerStoppedError
)
Error
()
string
{
func
(
self
l
istener
Has
StoppedError
)
Error
()
string
{
return
self
.
msg
}
var
listenerStoppedError
=
L
istenerStoppedError
{
"Listener stopped"
}
var
listenerStoppedError
=
l
istener
Has
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
N
ewStoppableTCPListener
(
addr
string
)
(
*
S
toppableTCPListener
,
error
)
{
func
n
ewStoppableTCPListener
(
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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment