rpcmux

package
v0.0.0-...-fbe9487 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Submits a request to the server.
	//
	// Parameter msg: The request message.
	//
	// Parameter ctx: A context.Context. Use context.Background() if unsure!
	//
	// If resp is not-nil, you should call resp.Release() after you are done.
	Request(msg Message, ctx context.Context) (resp *Response, err error)
}

type Message

type Message interface {
	Seq() uint64
	SetSeq(u uint64)
}

type Request

type Request struct {
	Msg Message
	// contains filtered or unexported fields
}

A Request, a server can respond to.

func (*Request) Context

func (r *Request) Context() context.Context

Get a context. Useful since the server can cancel requests.

func (*Request) Release

func (r *Request) Release()

This method should be called after the request has been processed (both successfully or unsuccessfully).

func (*Request) Reply

func (r *Request) Reply(m Message) (taken bool)

Replies with a message. Reply() calls m.SetSeq() with the correct sequence number.

Returns true if the message has been pushed to the Stream.Out queue, false otherwise.

func (*Request) ReplyDefault

func (r *Request) ReplyDefault()

This method works like Reply(), except, that it calls Stream.DefaultResponse to generate the Message.

This is useful, if the server does not know, how to respond. This is the case with request-forwarding applications.

type Response

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

func (*Response) Get

func (r *Response) Get() (Message, error)

Retrieves the Message, waiting if necessary.

The returned message is subject to recycling using a memory pool provided by the *Stream structure.

If you want to retain it beyond .Release() you must call .RetainMsg().

func (*Response) Release

func (r *Response) Release()

Should be called after the client is done with the response.

func (*Response) RetainMsg

func (r *Response) RetainMsg()

Saves the response message from recycling.

After this function, the user is responsible for recycling it, if memory pooling desired.

type Stream

type Stream struct {
	Err error
	Die <-chan struct{}
	In  <-chan Message
	Out chan<- Message

	// memory management
	InRelease func(m Message) // release messages, received through s.In

	// Support for canceling requests.
	Cancel   func() Message       // generate a cancel-message.
	IsCancel func(m Message) bool // detect a cancel-message.

	DefaultResponse func() Message // Generate default response message.
}

func (*Stream) Client

func (s *Stream) Client() (c Client)

func (*Stream) Serve

func (s *Stream) Serve() (requests <-chan *Request)

Jump to

Keyboard shortcuts

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