Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify the Arena implementation used by server. #565

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type Server struct {

// Handler for custom behavior of unknown methods
HandleUnknownMethod func(m capnp.Method) *Method

// Arena implementation
NewArena func() capnp.Arena
}

func (s *Server) String() string {
Expand Down Expand Up @@ -126,7 +129,7 @@ func (srv *Server) Send(ctx context.Context, s capnp.Send) (*capnp.Answer, capnp
if mm == nil {
return capnp.ErrorAnswer(s.Method, capnp.Unimplemented("unimplemented")), func() {}
}
args, err := sendArgsToStruct(s)
args, err := srv.sendArgsToStruct(s)
if err != nil {
return capnp.ErrorAnswer(mm.Method, err), func() {}
}
Expand Down Expand Up @@ -234,11 +237,22 @@ type serverBrand struct {
x any
}

func sendArgsToStruct(s capnp.Send) (capnp.Struct, error) {
func (srv *Server) sendArgsToStruct(s capnp.Send) (capnp.Struct, error) {
if s.PlaceArgs == nil {
return capnp.Struct{}, nil
}
_, seg := capnp.NewMultiSegmentMessage(nil)

if srv.NewArena == nil {
srv.NewArena = func() capnp.Arena {
// TODO: change to single segment?
return capnp.MultiSegment(nil)
}
}

_, seg, err := capnp.NewMessage(srv.NewArena())
if err != nil {
return capnp.Struct{}, err
}
st, err := capnp.NewRootStruct(seg, s.ArgsSize)
if err != nil {
return capnp.Struct{}, err
Expand Down
Loading