diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0131fb5e13..706025d4a7 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -616,7 +616,17 @@ func IpcSocketPath(ctx *cli.Context) (ipcpath string) { } func StartIPC(ethereum *eth.Ethereum, ctx *cli.Context) error { + 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())) @@ -631,18 +641,13 @@ func StartIPC(ethereum *eth.Ethereum, ctx *cli.Context) error { server.RegisterName("personal", accounts.NewPersonalService(ethereum.AccountManager())) server.RegisterName("shh", whisper.NewWhisperService(ethereum.Whisper())) - 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) @@ -652,11 +657,6 @@ func StartIPC(ethereum *eth.Ethereum, 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(ethereum, 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)