mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
rpc: move stdio transport to its own file
This commit is contained in:
parent
f951e23fb5
commit
032416e542
2 changed files with 66 additions and 40 deletions
|
|
@ -25,7 +25,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -181,45 +180,6 @@ func DialContext(ctx context.Context, rawurl string) (*Client, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type StdIOConn struct{}
|
|
||||||
|
|
||||||
func (io StdIOConn) Read(b []byte) (n int, err error) {
|
|
||||||
return os.Stdin.Read(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) Write(b []byte) (n int, err error) {
|
|
||||||
return os.Stdout.Write(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) Close() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) LocalAddr() net.Addr {
|
|
||||||
return &net.UnixAddr{Name: "stdio", Net: "stdio"}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) RemoteAddr() net.Addr {
|
|
||||||
return &net.UnixAddr{Name: "stdio", Net: "stdio"}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) SetDeadline(t time.Time) error {
|
|
||||||
return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) SetReadDeadline(t time.Time) error {
|
|
||||||
return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (io StdIOConn) SetWriteDeadline(t time.Time) error {
|
|
||||||
return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
|
||||||
}
|
|
||||||
func DialStdIO(ctx context.Context) (*Client, error) {
|
|
||||||
return newClient(ctx, func(_ context.Context) (net.Conn, error) {
|
|
||||||
return StdIOConn{}, nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func newClient(initctx context.Context, connectFunc func(context.Context) (net.Conn, error)) (*Client, error) {
|
func newClient(initctx context.Context, connectFunc func(context.Context) (net.Conn, error)) (*Client, error) {
|
||||||
conn, err := connectFunc(initctx)
|
conn, err := connectFunc(initctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
66
rpc/stdio.go
Normal file
66
rpc/stdio.go
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright 2018 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DialStdIO creates a client on stdin/stdout.
|
||||||
|
func DialStdIO(ctx context.Context) (*Client, error) {
|
||||||
|
return newClient(ctx, func(_ context.Context) (net.Conn, error) {
|
||||||
|
return stdioConn{}, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type stdioConn struct{}
|
||||||
|
|
||||||
|
func (io stdioConn) Read(b []byte) (n int, err error) {
|
||||||
|
return os.Stdin.Read(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) Write(b []byte) (n int, err error) {
|
||||||
|
return os.Stdout.Write(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) LocalAddr() net.Addr {
|
||||||
|
return &net.UnixAddr{Name: "stdio", Net: "stdio"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) RemoteAddr() net.Addr {
|
||||||
|
return &net.UnixAddr{Name: "stdio", Net: "stdio"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) SetDeadline(t time.Time) error {
|
||||||
|
return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) SetReadDeadline(t time.Time) error {
|
||||||
|
return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (io stdioConn) SetWriteDeadline(t time.Time) error {
|
||||||
|
return &net.OpError{Op: "set", Net: "stdio", Source: nil, Addr: nil, Err: errors.New("deadline not supported")}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue