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
8771fbf3
Unverified
Commit
8771fbf3
authored
Feb 12, 2019
by
Martin Holst Swende
Committed by
GitHub
Feb 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: make stdio usable over custom channels (#19046)
parent
b5d471a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
4 deletions
+16
-4
stdio.go
rpc/stdio.go
+16
-4
No files found.
rpc/stdio.go
View file @
8771fbf3
...
@@ -19,6 +19,7 @@ package rpc
...
@@ -19,6 +19,7 @@ package rpc
import
(
import
(
"context"
"context"
"errors"
"errors"
"io"
"net"
"net"
"os"
"os"
"time"
"time"
...
@@ -26,19 +27,30 @@ import (
...
@@ -26,19 +27,30 @@ import (
// DialStdIO creates a client on stdin/stdout.
// DialStdIO creates a client on stdin/stdout.
func
DialStdIO
(
ctx
context
.
Context
)
(
*
Client
,
error
)
{
func
DialStdIO
(
ctx
context
.
Context
)
(
*
Client
,
error
)
{
return
DialIO
(
ctx
,
os
.
Stdin
,
os
.
Stdout
)
}
// DialIO creates a client which uses the given IO channels
func
DialIO
(
ctx
context
.
Context
,
in
io
.
Reader
,
out
io
.
Writer
)
(
*
Client
,
error
)
{
return
newClient
(
ctx
,
func
(
_
context
.
Context
)
(
ServerCodec
,
error
)
{
return
newClient
(
ctx
,
func
(
_
context
.
Context
)
(
ServerCodec
,
error
)
{
return
NewJSONCodec
(
stdioConn
{}),
nil
return
NewJSONCodec
(
stdioConn
{
in
:
in
,
out
:
out
,
}),
nil
})
})
}
}
type
stdioConn
struct
{}
type
stdioConn
struct
{
in
io
.
Reader
out
io
.
Writer
}
func
(
io
stdioConn
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
func
(
io
stdioConn
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
return
os
.
Std
in
.
Read
(
b
)
return
io
.
in
.
Read
(
b
)
}
}
func
(
io
stdioConn
)
Write
(
b
[]
byte
)
(
n
int
,
err
error
)
{
func
(
io
stdioConn
)
Write
(
b
[]
byte
)
(
n
int
,
err
error
)
{
return
os
.
Std
out
.
Write
(
b
)
return
io
.
out
.
Write
(
b
)
}
}
func
(
io
stdioConn
)
Close
()
error
{
func
(
io
stdioConn
)
Close
()
error
{
...
...
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