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 Version = "1.0.2"
The Pivo package version numbers
Variables ¶
var ErrHubFlushErrors = errors.New("errors while flushing")
Error is thrown when disconnecting the connectors from the hub have raised some errors.
var ErrJoinQueueIsFull = errors.New("join queue is full")
Error is thrown when the join queue is full.
var ErrNoSuchConnector = errors.New("no such connector")
Error is thrown when a connection is not connected to the hub.
var ErrPortBufferIsFull = errors.New("port buffer is full")
Error is thrown when a connector has its port buffer full.
Functions ¶
This section is empty.
Types ¶
type Broadcast ¶
type Broadcast struct {
C chan []byte
}
A Broadcast represents a channel for sending messages to all instance of connectors on the hub.
type Connector ¶
type Connector interface { Close(error) error Receiver(OnReadCloser) error RemoteAddr() net.Addr Sender() chan []byte }
Connector is the interface that wraps the basic methods needed to send and receive the messages to and from a socket.
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 limit // interval is reached. A value of 10 would mean that // 10 more new connections may stop waiting to join // the hub, JoinLimitRateBurst uint // The maximum number of new connections waiting to // join the hub before ErrJoinQueueIsFull is being // returned. JoinMaxQueueSize uint // contains filtered or unexported fields }
A Hub is a collection of connectors with some specified settings.
func (*Hub) Join ¶
func (h *Hub) Join(c Connector, rc OnReadCloser, w Welcomer) error
Join adds the given connector to the hub. If a welcomer is specified, it sends the provided data through the connector before any broadcasted messages get delivered.
The connector's goroutine for receiving and sending messages will automatically be started and the given OnReadCloser will get notified either if there is data available to read or if the connector has been closed.
The caller needs not to worry about disconnecting the connector from the hub if remote has closed the connection. This is done and handled by default.
func (*Hub) Leave ¶
Leave disconnects the given connector from the hub. If reason is not nil, the remote end shall receive the reason. It is up to the connector to deliver the reason by its own mean.
func (*Hub) NewBroadcast ¶
NewBroadcast gives the caller a new broadcast channel and kicks off the goroutine responsible for delivering broadcasted message to the connectors currently connected.
type OnCloser ¶
OnCloser is the interface that requires a method to call upon disconnection of a connector.
type OnReadCloser ¶
OnReadCloser wraps the basic methods needed to be notified when data has been read or the connector has closed.