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 ¶
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)) snapshot := c.Snapshot() brand := snapshot.Brand() snapshot.Release() if brand, ok := server.IsServer(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 ¶
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 Server ¶
type Server struct { // Handler for custom behavior of unknown methods HandleUnknownMethod func(m capnp.Method) *Method // Arena implementation NewArena func() capnp.Arena // 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.
type Shutdowner ¶
type Shutdowner interface {
Shutdown()
}
Shutdowner is the interface that wraps the Shutdown method.