server

package
v3.0.0-alpha-29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2023 License: MIT Imports: 7 Imported by: 74

Documentation

Overview

Package server provides runtime support for implementing Cap'n Proto interfaces locally.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsServer

func IsServer(brand capnp.Brand) (_ any, ok bool)

IsServer reports whether a brand returned by capnp.Client.Brand originated from Server.Brand, and returns the brand argument passed to New.

Example
x := int(42)
c := capnp.NewClient(server.New([]server.Method{}, x, nil))
if brand, ok := server.IsServer(c.State().Brand); ok {
	fmt.Println("Client is a server, got brand:", brand)
}
Output:

Client is a server, got brand: 42

Types

type Call

type Call struct {
	// contains filtered or unexported fields
}

Call holds the state of an ongoing capability method call. A Call cannot be used after the server method returns.

func (*Call) AllocResults

func (c *Call) AllocResults(sz capnp.ObjectSize) (capnp.Struct, error)

AllocResults allocates the results struct. It is an error to call AllocResults more than once.

func (*Call) Args

func (c *Call) Args() capnp.Struct

Args returns the call's arguments. Args is not safe to reference after a method implementation returns. Args is safe to call and read from multiple goroutines.

func (*Call) Go

func (c *Call) Go()

Go is a function that is called to unblock future calls; by default a server only accepts one method call at a time, waiting until the method returns before servicing the next method in the queue. calling Go spawns another goroutine to service additional Calls in the queue, allowing the current goroutine to block, do expensive computation, etc. without holding up other calls. If Go is called, the calling Goroutine exits when the method returns, so that there is never more than one goroutine pulling things from the queue.

Go need not be the first call in a function nor is it required. short functions can return without calling Go.

type Method

type Method struct {
	capnp.Method
	Impl func(context.Context, *Call) error
}

A Method describes a single capability method on a server object.

type Server

type Server struct {

	// Handler for custom behavior of unknown methods
	HandleUnknownMethod func(m capnp.Method) *Method
	// contains filtered or unexported fields
}

A Server is a locally implemented interface. It implements the capnp.ClientHook interface.

func New

func New(methods []Method, brand any, shutdown Shutdowner) *Server

New returns a client hook that makes calls to a set of methods. If shutdown is nil then the server's shutdown is a no-op. The server guarantees message delivery order by blocking each call on the return of the previous call or a call to Call.Go.

func (*Server) Brand

func (srv *Server) Brand() capnp.Brand

Brand returns a value that will match IsServer.

func (*Server) Recv

func (srv *Server) Recv(ctx context.Context, r capnp.Recv) capnp.PipelineCaller

Recv starts a method call.

func (*Server) Send

func (srv *Server) Send(ctx context.Context, s capnp.Send) (*capnp.Answer, capnp.ReleaseFunc)

Send starts a method call.

func (*Server) Shutdown

func (srv *Server) Shutdown()

Shutdown arranges for Shutdown to be called on the Shutdowner passed into NewServer after outstanding all calls have been serviced. Shutdown must not be called more than once.

func (*Server) String

func (s *Server) String() string

type Shutdowner

type Shutdowner interface {
	Shutdown()
}

Shutdowner is the interface that wraps the Shutdown method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL