aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/stdio.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2018-10-15 16:56:04 +0800
committerGitHub <noreply@github.com>2018-10-15 16:56:04 +0800
commit2e98631c5e5724bea1a29b877929b4911bf50b86 (patch)
treee71da8eb8b99cf7f2d81249b33c8de0267685c5e /rpc/stdio.go
parent6566a0a3b82f5d24d478d3876d5fa2b1b0e8684c (diff)
downloadgo-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.gz
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.bz2
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.lz
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.xz
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.zst
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.zip
rpc: fix client shutdown hang when Close races with Unsubscribe (#17894)
Fixes #17837
Diffstat (limited to 'rpc/stdio.go')
-rw-r--r--rpc/stdio.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/rpc/stdio.go b/rpc/stdio.go
new file mode 100644
index 000000000..ea552cca2
--- /dev/null
+++ b/rpc/stdio.go
@@ -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")}
+}