added Windows support for experimental IPC interface

This commit is contained in:
Bas van Kervel 2015-11-27 09:23:08 +01:00
parent e09cd88a7b
commit 2f795aaef9
2 changed files with 19 additions and 14 deletions

View file

@ -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)

View file

@ -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)