Documentation ¶
Index ¶
Constants ¶
const ( Unknown uint8 = iota Call Reply Error Post Event Capability Cancel Cancelled )
Message types:
const HeaderSize = 28
HeaderSize is the size of a message header. It is the minimum size of a message.
const Magic = uint32(0x42dead42)
Magic is a constant to discriminate between message and garbage.
const MaxPayloadSize = uint32(10 * 1024 * 1024)
MaxPayloadSize limits the payload size of a message (10MB)
const Version = 0
Version is the supported version of the protocol.
Variables ¶
var ErrConsumerBlocked = errors.New("message dropped: consumer blocked")
ErrConsumerBlocked is returned when the message cannot be sent to the consumer queue (the queue is full).
var ErrNoHandler = errors.New("message dropped: no handler registered")
ErrNoHandler is returned when there is no handler registered.
var ErrNoMatch = errors.New("message dropped: no handler match")
ErrNoMatch is returned when the message did not match any handler
Functions ¶
Types ¶
type EndPoint ¶
type EndPoint interface { fmt.Stringer // Send pushes the message into the network. Send(m Message) error // ReceiveAny returns a chanel to receive a single message. ReceiveAny() (chan *Message, error) // MakeHandler registers the associated Filter and queue to // the incomming traffic from the EndPoint. Writing to the // queue must not block otherwise messages are discarded. If // an error occurs, closer is called, the consumer is closed. // closer can be nil. Do not attempt to add another handler // from within a Filter. Filter must not block. MakeHandler(f Filter, queue chan<- *Message, cl Closer) int // AddHandler creates a queue of 10 messages and spawn a // goroutine to forward those events into the consumer, then // calls MakeHandler. Do not attempt to add another handler // from within a Filter. Filter must not block. AddHandler(f Filter, c Consumer, cl Closer) int // RemoveHandler removes the associated Filter and Consumer. // RemoveHandler must not be called from within the Filter: use // the Filter returned value keep for this purpose. RemoveHandler(id int) error // Close close the underlying connection Close() error }
EndPoint reprensents a network socket capable of sending and receiving messages.
func ConnEndPoint ¶
ConnEndPoint returns an EndPoint using a go connection.
func DialEndPoint ¶
DialEndPoint construct an endpoint by contacting a given address.
func EndPointFinalizer ¶
EndPointFinalizer creates a new EndPoint and let you process it before it start handling messages. This allows you to add handler or/and avoid data races.
func NewEndPoint ¶
NewEndPoint returns an EndPoint which already process incomming messages. Since no handler have been register at the time of the creation of the EndPoint, any message receive will be droped until and Handler is registered. Prefer EndPointFinalizer for a safe way to construct EndPoint.
type Filter ¶
Filter returns true if given message shall be processed by a Consumer. Returns two values: - matched: true if the message should be processed by the Consumer. - keep: true if the handler shall be kept in the dispatcher.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler represents a client of a incomming message stream. It contains a filter used to decided if the message shall be sent to the handler, consumer will receive the messages in order of arrival. If an error occurs, closer is called, then the consumer is closed.
type Header ¶
type Header struct { Magic uint32 // magic number ID uint32 // message id Size uint32 // size of the payload Version uint16 // protocol version Type uint8 // type of the message Flags uint8 // flags Service uint32 // service id Object uint32 // object id Action uint32 // function or event id }
Header represents a message header.
func NewHeader ¶
NewHeader construct a message header given some parameters. The size of the message is zero.
type KeyNetContext ¶
type KeyNetContext uint32
KeyNetContext represents an entry in the sream context.
const ( // DialAddress is the addressed dialed. DialAddress KeyNetContext = iota // ListenAddress is the addressed listen. ListenAddress )
type Message ¶
Message represents a QiMessaging message.
func NewMessage ¶
NewMessage assemble an header and a payload to create a message. The size filed of the header is adjusted if necessary.
type Stream ¶
Stream represents a network connection. Stream abstracts connections to allow for various transports.
func ConnStream ¶
ConnStream construct a Stream from a connection.
func PipeStream ¶
PipeStream returns a Stream based on the pipe:// protocol