From b29774c4f2d7368910716fd3400617f4e4d86a27 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Fri, 27 Nov 2015 09:23:08 +0100 Subject: [PATCH] added Windows support for experimental IPC interface --- cmd/utils/flags.go | 25 +++++++++++-------------- rpc/comms/ipc.go | 5 +++++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f7825d268c..cb3eb78197 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -791,8 +791,14 @@ func StartIPC(stack *node.Node, ctx *cli.Context) error { if err := stack.Service(&shh); err != nil { return err } - + config := comms.IpcConfig{ + Endpoint: IpcSocketPath(ctx), + } if ctx.GlobalIsSet(IPCExperimental.Name) { + listener, err := comms.CreateListener(config) + if err != nil { + return err + } server := rpc.NewServer() server.RegisterName("eth", accounts.NewAccountService(ethereum.AccountManager())) @@ -807,18 +813,13 @@ func StartIPC(stack *node.Node, ctx *cli.Context) error { server.RegisterName("personal", accounts.NewPersonalService(ethereum.AccountManager())) server.RegisterName("shh", whisper.NewWhisperService(shh)) - ipcEndpoint := IpcSocketPath(ctx) - os.RemoveAll(ipcEndpoint) - l, err := net.ListenUnix("unix", &net.UnixAddr{Name: ipcEndpoint, Net: "unix"}) - if err != nil { - return err - } go func() { - glog.Infof("IPC endpoint(%s)\n", ipcEndpoint) + glog.Infof("IPC Service endpoint(%s)\n", config.Endpoint) for { - conn, err := l.Accept() + conn, err := listener.Accept() if err != nil { - panic(err) + glog.Errorf("%v\n", err) + continue } codec := rpc.NewJSONCodec(conn) go server.ServeCodec(codec) @@ -828,10 +829,6 @@ func StartIPC(stack *node.Node, ctx *cli.Context) error { return nil } - config := comms.IpcConfig{ - Endpoint: IpcSocketPath(ctx), - } - initializer := func(conn net.Conn) (comms.Stopper, shared.EthereumApi, error) { fe := useragent.NewRemoteFrontend(conn, ethereum.AccountManager()) xeth := xeth.New(stack, fe) diff --git a/rpc/comms/ipc.go b/rpc/comms/ipc.go index 67edbe9aea..16d735c687 100644 --- a/rpc/comms/ipc.go +++ b/rpc/comms/ipc.go @@ -124,6 +124,11 @@ func StartIpc(cfg IpcConfig, codec codec.Codec, initializer InitFunc) error { return nil } +// CreateListener creates an listener, on Unix platforms this is a unix socket, on Windows this is a named pipe +func CreateListener(cfg IpcConfig) (net.Listener, error) { + return ipcListen(cfg) +} + func ipcLoop(cfg IpcConfig, codec codec.Codec, initializer InitFunc, l net.Listener) { glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint) defer os.Remove(cfg.Endpoint)