rpc: new RPC implementation with pub/sub support
This commit is contained in:
@@ -69,13 +69,28 @@ func (self *ipcClient) SupportedModules() (map[string]string, error) {
|
||||
req := shared.Request{
|
||||
Id: 1,
|
||||
Jsonrpc: "2.0",
|
||||
Method: "modules",
|
||||
Method: "rpc_modules",
|
||||
}
|
||||
|
||||
if err := self.coder.WriteResponse(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, _ := self.coder.ReadResponse()
|
||||
if sucRes, ok := res.(*shared.SuccessResponse); ok {
|
||||
data, _ := json.Marshal(sucRes.Result)
|
||||
modules := make(map[string]string)
|
||||
if err := json.Unmarshal(data, &modules); err == nil {
|
||||
return modules, nil
|
||||
}
|
||||
}
|
||||
|
||||
// old version uses modules instead of rpc_modules, this can be removed after full migration
|
||||
req.Method = "modules"
|
||||
if err := self.coder.WriteResponse(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res, err := self.coder.ReadResponse()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -108,6 +123,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)
|
||||
|
Reference in New Issue
Block a user