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
ffda2c64
Unverified
Commit
ffda2c64
authored
May 04, 2023
by
s7v7nislands
Committed by
GitHub
May 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: use atomic types (#27214)
rpc: use atomic type
parent
dde2da0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
9 deletions
+9
-9
client.go
rpc/client.go
+2
-2
server.go
rpc/server.go
+5
-5
stdioui.go
signer/core/stdioui.go
+2
-2
No files found.
rpc/client.go
View file @
ffda2c64
...
...
@@ -79,7 +79,7 @@ type Client struct {
isHTTP
bool
// connection type: http, ws or ipc
services
*
serviceRegistry
idCounter
u
int32
idCounter
atomic
.
U
int32
// This function, if non-nil, is called when the connection is lost.
reconnectFunc
reconnectFunc
...
...
@@ -263,7 +263,7 @@ func (c *Client) RegisterName(name string, receiver interface{}) error {
}
func
(
c
*
Client
)
nextID
()
json
.
RawMessage
{
id
:=
atomic
.
AddUint32
(
&
c
.
idCounter
,
1
)
id
:=
c
.
idCounter
.
Add
(
1
)
return
strconv
.
AppendUint
(
nil
,
uint64
(
id
),
10
)
}
...
...
rpc/server.go
View file @
ffda2c64
...
...
@@ -48,7 +48,7 @@ type Server struct {
mutex
sync
.
Mutex
codecs
map
[
ServerCodec
]
struct
{}
run
int32
run
atomic
.
Bool
}
// NewServer creates a new server instance with no registered handlers.
...
...
@@ -56,8 +56,8 @@ func NewServer() *Server {
server
:=
&
Server
{
idgen
:
randomIDGenerator
(),
codecs
:
make
(
map
[
ServerCodec
]
struct
{}),
run
:
1
,
}
server
.
run
.
Store
(
true
)
// Register the default service providing meta information about the RPC service such
// as the services and methods it offers.
rpcService
:=
&
RPCService
{
server
}
...
...
@@ -95,7 +95,7 @@ func (s *Server) trackCodec(codec ServerCodec) bool {
s
.
mutex
.
Lock
()
defer
s
.
mutex
.
Unlock
()
if
atomic
.
LoadInt32
(
&
s
.
run
)
==
0
{
if
!
s
.
run
.
Load
()
{
return
false
// Don't serve if server is stopped.
}
s
.
codecs
[
codec
]
=
struct
{}{}
...
...
@@ -114,7 +114,7 @@ func (s *Server) untrackCodec(codec ServerCodec) {
// this mode.
func
(
s
*
Server
)
serveSingleRequest
(
ctx
context
.
Context
,
codec
ServerCodec
)
{
// Don't serve if server is stopped.
if
atomic
.
LoadInt32
(
&
s
.
run
)
==
0
{
if
!
s
.
run
.
Load
()
{
return
}
...
...
@@ -144,7 +144,7 @@ func (s *Server) Stop() {
s
.
mutex
.
Lock
()
defer
s
.
mutex
.
Unlock
()
if
atomic
.
CompareAndSwapInt32
(
&
s
.
run
,
1
,
0
)
{
if
s
.
run
.
CompareAndSwap
(
true
,
false
)
{
log
.
Debug
(
"RPC server shutting down"
)
for
codec
:=
range
s
.
codecs
{
codec
.
close
()
...
...
signer/core/stdioui.go
View file @
ffda2c64
...
...
@@ -25,7 +25,7 @@ import (
)
type
StdIOUI
struct
{
client
rpc
.
Client
client
*
rpc
.
Client
}
func
NewStdIOUI
()
*
StdIOUI
{
...
...
@@ -33,7 +33,7 @@ func NewStdIOUI() *StdIOUI {
if
err
!=
nil
{
log
.
Crit
(
"Could not create stdio client"
,
"err"
,
err
)
}
ui
:=
&
StdIOUI
{
client
:
*
client
}
ui
:=
&
StdIOUI
{
client
:
client
}
return
ui
}
...
...
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