-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathclient.go
More file actions
75 lines (60 loc) · 1.91 KB
/
client.go
File metadata and controls
75 lines (60 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package testharness
import (
"io"
"net/rpc"
"net/rpc/jsonrpc"
)
// Client is the typed parent-side wrapper around the JSON-RPC channel
// to the child helper process. It hides method-name strings, the Empty
// placeholder pointers, and the wire-vs-domain type translation.
type Client struct {
rpc *rpc.Client
conn io.Closer
}
// NewClient wraps an already-connected duplex stream (typically one
// half of a socketpair handed off via cmd.ExtraFiles). Closing the
// returned Client closes the underlying conn.
func NewClient(conn io.ReadWriteCloser) *Client {
return &Client{
rpc: jsonrpc.NewClient(conn),
conn: conn,
}
}
func (c *Client) Bootstrap(args BootstrapArgs) error {
return c.rpc.Call("Lifecycle.Bootstrap", &args, &BootstrapReply{})
}
func (c *Client) WaitReady() error {
return c.rpc.Call("Lifecycle.WaitReady", &Empty{}, &Empty{})
}
func (c *Client) Shutdown() error {
return c.rpc.Call("Lifecycle.Shutdown", &Empty{}, &Empty{})
}
func (c *Client) Pause() error {
return c.rpc.Call("Paging.Pause", &Empty{}, &Empty{})
}
func (c *Client) Resume() error {
return c.rpc.Call("Paging.Resume", &Empty{}, &Empty{})
}
func (c *Client) PageStates() ([]PageStateEntry, error) {
var reply PageStatesReply
if err := c.rpc.Call("Paging.States", &Empty{}, &reply); err != nil {
return nil, err
}
return reply.Entries, nil
}
func (c *Client) InstallBarrier(addr uintptr, point Point) (uint64, error) {
var reply FaultBarrierReply
if err := c.rpc.Call("Barriers.Install", &FaultBarrierArgs{Addr: uint64(addr), Point: uint8(point)}, &reply); err != nil {
return 0, err
}
return reply.Token, nil
}
func (c *Client) WaitFaultHeld(token uint64) error {
return c.rpc.Call("Barriers.WaitHeld", &TokenArgs{Token: token}, &Empty{})
}
func (c *Client) ReleaseFault(token uint64) error {
return c.rpc.Call("Barriers.Release", &TokenArgs{Token: token}, &Empty{})
}
func (c *Client) Close() error {
return c.conn.Close()
}