From 60c2ccd99cd9acdb628a9ba5e16ad0e7e52b7e17 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Tue, 16 Jun 2015 11:16:50 +0200 Subject: made ipc handler generic and reusable --- rpc/comms/ipc_unix.go | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'rpc/comms/ipc_unix.go') diff --git a/rpc/comms/ipc_unix.go b/rpc/comms/ipc_unix.go index 5a94fd1e0..131fb86f2 100644 --- a/rpc/comms/ipc_unix.go +++ b/rpc/comms/ipc_unix.go @@ -3,7 +3,6 @@ package comms import ( - "io" "net" "os" @@ -11,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" - "github.com/ethereum/go-ethereum/rpc/shared" ) func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) { @@ -40,32 +38,7 @@ func startIpc(cfg IpcConfig, codec codec.Codec, api api.EthereumApi) error { continue } - go func(conn net.Conn) { - codec := codec.New(conn) - - for { - req, err := codec.ReadRequest() - if err == io.EOF { - codec.Close() - return - } else if err != nil { - glog.V(logger.Error).Infof("IPC recv err - %v\n", err) - codec.Close() - return - } - - var rpcResponse interface{} - res, err := api.Execute(req) - - rpcResponse = shared.NewRpcResponse(req.Id, req.Jsonrpc, res, err) - err = codec.WriteResponse(rpcResponse) - if err != nil { - glog.V(logger.Error).Infof("IPC send err - %v\n", err) - codec.Close() - return - } - } - }(conn) + go handle(conn, api, codec) } os.Remove(cfg.Endpoint) -- cgit v1.2.3 From f20256377731097c9478ede750efffd46d83b494 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Thu, 18 Jun 2015 18:23:13 +0200 Subject: added attach over ipc command --- rpc/comms/ipc_unix.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'rpc/comms/ipc_unix.go') diff --git a/rpc/comms/ipc_unix.go b/rpc/comms/ipc_unix.go index 131fb86f2..b5eec92db 100644 --- a/rpc/comms/ipc_unix.go +++ b/rpc/comms/ipc_unix.go @@ -18,7 +18,17 @@ func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) { return nil, err } - return &ipcClient{codec.New(c)}, nil + return &ipcClient{cfg.Endpoint, codec, codec.New(c)}, nil +} + +func (self *ipcClient) reconnect() error { + self.coder.Close() + c, err := net.DialUnix("unix", nil, &net.UnixAddr{self.endpoint, "unix"}) + if err == nil { + self.coder = self.codec.New(c) + } + + return err } func startIpc(cfg IpcConfig, codec codec.Codec, api api.EthereumApi) error { -- cgit v1.2.3 From 2e0b56a72b3eafc89938003da29c06496ac9ad4e Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 22 Jun 2015 12:47:32 +0200 Subject: added RPC start/stop support --- rpc/comms/ipc_unix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rpc/comms/ipc_unix.go') diff --git a/rpc/comms/ipc_unix.go b/rpc/comms/ipc_unix.go index b5eec92db..295eb916b 100644 --- a/rpc/comms/ipc_unix.go +++ b/rpc/comms/ipc_unix.go @@ -8,8 +8,8 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/rpc/shared" ) func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) { @@ -31,7 +31,7 @@ func (self *ipcClient) reconnect() error { return err } -func startIpc(cfg IpcConfig, codec codec.Codec, api api.EthereumApi) error { +func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error { os.Remove(cfg.Endpoint) // in case it still exists from a previous run l, err := net.ListenUnix("unix", &net.UnixAddr{Name: cfg.Endpoint, Net: "unix"}) -- cgit v1.2.3