hashicorp / hashicorp/go-plugin

how to use plugin.MuxBroker to pass io.Reader as param not interface api implemented interface of plugin

Open
#188 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.1k
Forks
511
Avg merge
22h 47m
Merged PRs (30d)
4

Description

hello
i can't pass the parameters like io.Reader from client ro server with MuxBroker.
i check and find out that the stuct "MuxBroker" only is use to transport interface api implemented interface of plugin
is my view wrong ?

it respenses err when i call "Greet"

```
func (p *GreeterPlugin) Server(b *plugin.MuxBroker) (interface{}, error) {
return &GreeterRPCServer{Impl: p.Impl, b: b}, nil
}

func (GreeterPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &GreeterRPC{client: c, b: b}, nil
}
var id uint32

func (g *GreeterRPC) Greet() string {
var resp string
go func() {
id = g.b.NextId()
g.b.AcceptAndServe(id, g.client)
}()
err := g.client.Call("Plugin.Greet", new(interface{}), &resp)
if err != nil {
// You usually want your interfaces to return errors. If they don't,
// there isn't much other choice here.
panic(err)
}

return resp
}

func (s *GreeterRPCServer) Greet(args interface{}, resp *string) error {

conn,err := s.b.Dial(id)
if err != nil {
logrus.Warn("--s.b.Dial(id)--", err)
return err
}
b,err := io.ReadAll(conn)
if err != nil {
logrus.Warn("--io.ReadAll(conn)--", err)
return err
}
logrus.Warn("--GreeterRPCServer--", b)
*resp = s.Impl.Greet()
return nil
}
```

err
```
2022-03-10T16:43:35.235+0800 [DEBUG] plugin.greeter: plugin address: address=/tmp/plugin684002887 network=unix timestamp=2022-03-10T16:43:35.235+0800
2022-03-10T16:43:35.235+0800 [DEBUG] plugin: using plugin: version=1
2022/03/10 16:43:35 rpc.Register: method "Len" has 1 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: method "Read" has 2 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: reply type of method "ReadAt" is not a pointer: "int64"
2022/03/10 16:43:35 rpc.Register: method "ReadByte" has 1 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: method "ReadRune" has 1 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: method "Reset" has 2 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: reply type of method "Seek" is not a pointer: "int"
2022-03-10T16:43:35.236+0800 [DEBUG] plugin.greeter: time="2022-03-10T16:43:35+08:00" level=warning msg="--conn.LocalAddr()--/tmp/plugin684002887"
2022/03/10 16:43:35 rpc.Register: method "Size" has 1 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: method "UnreadByte" has 1 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: method "UnreadRune" has 1 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: method "WriteTo" has 2 input parameters; needs exactly three
2022/03/10 16:43:35 rpc.Register: type Plugin has no exported methods of suitable type
2022/03/10 16:43:35 [ERR] go-plugin: plugin dispense error: rpc.Register: type Plugin has no exported methods of suitable type

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.