server

package
v3.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 6 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) (_ interface{}, 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, 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) Ack

func (c *Call) Ack()

Ack is a function that is called to acknowledge the delivery of the RPC call, allowing other RPC methods to be called on the server. After the first call, subsequent calls to Ack do nothing.

Ack need not be the first call in a function nor is it required. Since the function's return is also an acknowledgment of delivery, short functions can return without calling Ack. However, since the server will not return an Answer until the delivery is acknowledged, failure to acknowledge a call before waiting on an RPC may cause deadlocks.

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.

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 Policy

type Policy struct {
	// MaxConcurrentCalls is the maximum number of methods allowed to be
	// executing on a single Server simultaneously.  Attempts to make more
	// calls than this limit will result in immediate error answers.
	//
	// If this is zero, then a reasonably small default is used.
	MaxConcurrentCalls int

	// AnswerQueueSize is the maximum number of methods allowed to be
	// enqueued on a single returned Answer while it is unresolved.
	// Attempts to enqueue more calls than this limit will result in
	// immediate error answers.
	//
	// If this is zero, then a reasonably small default is used.
	AnswerQueueSize int
}

Policy is a set of behavioral parameters for a Server. They're not specific to a particular server and are generally set at an application level. Library functions are encouraged to accept a Policy from a caller instead of creating their own.

type Server

type Server struct {
	// 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 interface{}, shutdown Shutdowner, policy *Policy) *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 or acknowledgment of the previous call. See Call.Ack for more details.

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 waits for ongoing calls to finish and calls Shutdown on the Shutdowner passed into NewServer. Shutdown must not be called more than once.

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