rpc: add new client, use it everywhere
The new client implementation supports concurrent requests, subscriptions and replaces the various ad hoc RPC clients throughout go-ethereum.
This commit is contained in:
@ -22,16 +22,27 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"gopkg.in/natefinch/npipe.v2"
|
||||
)
|
||||
|
||||
// This is used if the dialing context has no deadline. It is much smaller than the
|
||||
// defaultDialTimeout because named pipes are local and there is no need to wait so long.
|
||||
const defaultPipeDialTimeout = 2 * time.Second
|
||||
|
||||
// ipcListen will create a named pipe on the given endpoint.
|
||||
func ipcListen(endpoint string) (net.Listener, error) {
|
||||
return npipe.Listen(endpoint)
|
||||
}
|
||||
|
||||
// newIPCConnection will connect to a named pipe with the given endpoint as name.
|
||||
func newIPCConnection(endpoint string) (net.Conn, error) {
|
||||
timeout := 5 * time.Second
|
||||
func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) {
|
||||
timeout := defaultPipeDialTimeout
|
||||
if deadline, ok := ctx.Deadline(); ok {
|
||||
timeout = deadline.Sub(time.Now())
|
||||
if timeout < 0 {
|
||||
timeout = 0
|
||||
}
|
||||
}
|
||||
return npipe.DialTimeout(endpoint, timeout)
|
||||
}
|
||||
|
Reference in New Issue
Block a user