Documentation ¶
Overview ¶
Package pivo provides the base implementation for a hub of sockets.
Index ¶
Constants ¶
const DefaultJoinLimitRateBurst = 32
Default value for the allowed burst over the join limit. Currently defined as a maximum of 32 more connections.
const DefaultJoinLimitRateInterval = time.Second / 64
Default value for the join rate limit. Currently defined as a maximum of 64 per seconds.
const DefaultJoinMaxQueueSize = 256
Default value for the size of the join queue. Currently defined as 256 pending connections before new ones are discarded.
const IsBinaryMessage = 1
Marker for binary message type
const IsTextMessage = 0
Marker for text message type
const Version = "2.0.1"
The Pivo package version numbers
Variables ¶
var ErrJoinQueueIsFull = errors.New("join queue is full")
Error is thrown when the join queue is full.
var ErrPortBufferIsFull = errors.New("port buffer is full")
Error is thrown when a connector has its port buffer full.
var ErrShouldNotReachThis = errors.New("should not reach this")
Error is thrown when unexpected code path is reached.
Functions ¶
This section is empty.
Types ¶
type Connector ¶
type Connector interface { Close(error) error Protocol() string RemoteAddr() net.Addr Send(*Message) error }
Connector is the interface that wraps the basic methods needed to use a connector with the hub.
type Hub ¶
type Hub struct { // The interval at which new connections are processed. // A Duration of time.Second / 100 would mean hundred // of new connections are processed in a second. JoinLimitRateInterval time.Duration // The size of the burst allowed when the join rate limit // is reached. A value of 10 would mean that 10 extra // connections may wait to join the hub. JoinLimitRateBurst uint // The maximum number of new connections waiting to // join the hub before ErrJoinQueueIsFull is being // thrown. JoinMaxQueueSize uint // contains filtered or unexported fields }
A Hub is a collection of connectors with some specified settings.
func (*Hub) StartAndServe ¶
StartAndServe serves the hub until Stop() is requested.
type Message ¶
type Message struct { Data []byte // Bytes of data From Connector // Original connector Type int // Type of data }
Message is a data structure with bytes of data, type of data, and its original connector.
func BinaryMessage ¶
BinaryMessage formats a binary message and returns a pointer to it.
func TextMessage ¶
TextMessage formats a text message and returns a pointer to it.
type OnBinaryReadCloser ¶
type OnBinaryReadCloser interface { OnBinaryReader OnCloser }
OnBinaryReadCloser is the interface that wraps basic methods both for reading binary data and getting notified about a closed connection.
type OnBinaryReader ¶
OnBinaryReader is called when binary data is read from a connector.
type OnCloser ¶
OnCloser is the interface that requires a method to call upon disconnection of a connector.
type OnHubBroadcaster ¶
OnHubBroadcaster is triggered before the message is delivered. Callee may alter the message in any way as well as provide a different list of recipients ports. If error is thrown, broadcast will not occur at all.
type OnHubCloser ¶
type OnHubCloser interface {
OnHubClose(Ports)
}
OnHubCloser is triggered right before the hub stops. The map of connected connectors is provided and is guaranteed to be accurate at the time the callee has it.
type OnHubJoiner ¶
OnHubJoiner is triggered before a connector may join the hub. If error is thrown, join will not occur at all.
type OnHubLeaver ¶
type OnHubLeaver interface {
OnHubLeave(Connector)
}
OnHubLeaver is triggered before a connector disjoin the hub. Nothing may prevent this from happening at this stage.
type OnReadCloser ¶
OnReadCloser wraps the basic methods needed to be notified when data has been read or the connector has closed.
type OnReader ¶
type OnReader interface { OnBinaryReader OnTextReader }
OnReader is the interface that wraps the methods called when data is read from a connector.
type OnTextReadCloser ¶
type OnTextReadCloser interface { OnTextReader OnCloser }
OnTextReadCloser is the interface that wraps basic methods both for reading text data and getting notified about a closed connection.
type OnTextReader ¶
OnTextReader is called when text data is read from a connector.
Directories ¶
Path | Synopsis |
---|---|
bin
|
|
Package ws implements the Pivo/Websocket connector.
|
Package ws implements the Pivo/Websocket connector. |