diff --git a/system/socket.go b/system/socket.go index da63996..39a46ee 100644 --- a/system/socket.go +++ b/system/socket.go @@ -7,28 +7,8 @@ import ( "math" "github.com/tetratelabs/wazero/api" - "github.com/wetware/go/util" ) -type SocketConfig struct { - Mailbox io.Writer - Deliver api.Function -} - -func (c SocketConfig) Bind(ctx context.Context) Proc { - if c.Deliver == nil { - return util.Failf[Proc]("missing export: deliver") - } - - return Proc_ServerToClient(c.Build(ctx)) -} - -func (c SocketConfig) Build(ctx context.Context) (sock Socket) { - sock.Buffer = c.Mailbox - sock.Deliver = c.Deliver - return -} - // Socket is an interface to a process. type Socket struct { // Buffer is an io.Writer that accumulates bytes in preparation for diff --git a/system/socket_test.go b/system/socket_test.go index 3a99c11..35fb9db 100644 --- a/system/socket_test.go +++ b/system/socket_test.go @@ -23,10 +23,12 @@ func TestSocket(t *testing.T) { // or not... deliver := &mockFn{Name: "deliver", Want: "test"} - proc := system.SocketConfig{ - Mailbox: deliver.Mailbox(), + sock := system.Socket{ + Buffer: deliver.Mailbox(), Deliver: deliver, - }.Bind(ctx) + } + + proc := system.Proc_ServerToClient(sock) defer proc.Release() f, release := proc.Handle(ctx, func(p system.Proc_handle_Params) error { diff --git a/system/system.go b/system/system.go index 35b57fd..e5b845c 100644 --- a/system/system.go +++ b/system/system.go @@ -12,6 +12,7 @@ import ( "capnproto.org/go/capnp/v3/exp/bufferpool" "github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero/api" + "github.com/wetware/go/util" ) const ModuleName = "ww" @@ -28,10 +29,15 @@ func (m *Module) Stdin() io.Reader { // Boot returns the system's bootstrap client. This capability is // analogous to the "root" user in a Unix system. func (m *Module) Boot(ctx context.Context, mod api.Module) capnp.Client { - socket := SocketConfig{ - Mailbox: &m.stdin, - Deliver: mod.ExportedFunction("deliver"), - }.Build(ctx) + deliver := mod.ExportedFunction("deliver") + if deliver == nil { + return util.Failf[capnp.Client]("missing export: deliver") + } + + socket := Socket{ + Buffer: &m.stdin, + Deliver: deliver, + } server := Proc_NewServer(socket) return capnp.NewClient(server)