pivo

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2015 License: BSD-2-Clause Imports: 4 Imported by: 2

README

Pivo's Hub of Sockets for Go

Pivo is Go package for broadcasting messages through a virtual hub

Getting started

Documentation
Installation

Install the Pivo library using the following go command.

$ go get gopkg.in/pivo.v1
Dependencies

Pivo has the following dependency for the websocket connector.

License

Use of this source code is governed by a Simplified BSD license that can be found in the LICENSE file.

Documentation

Overview

Package pivo provides the base implementation for a hub of sockets.

Index

Constants

View Source
const DefaultJoinLimitRateBurst = 32

Default value for the allowed burst over the join limit. Currently defined as a maximum of 32 more connections.

View Source
const DefaultJoinLimitRateInterval = time.Second / 64

Default value for the join rate limit. Currently defined as a maximum of 64 per seconds.

View Source
const DefaultJoinMaxQueueSize = 256

Default value for the size of the join queue. Currently defined as 256 pending connections before new ones are discarded.

View Source
const Version = "1.0.2"

The Pivo package version numbers

Variables

View Source
var ErrHubFlushErrors = errors.New("errors while flushing")

Error is thrown when disconnecting the connectors from the hub have raised some errors.

View Source
var ErrJoinQueueIsFull = errors.New("join queue is full")

Error is thrown when the join queue is full.

View Source
var ErrNoSuchConnector = errors.New("no such connector")

Error is thrown when a connection is not connected to the hub.

View Source
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.

func (*Broadcast) Close

func (b *Broadcast) Close()

Close should be called when a broadcast channel is no longer used. Both the created channel and goroutine will be taken down.

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 NewHub

func NewHub() *Hub

NewHub instantiate a new hub with default settings.

func (*Hub) Flush

func (h *Hub) Flush(reason error) (error, []error)

Flush disconnects all connectors from the hub without actually stopping it.

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

func (h *Hub) Leave(c Connector, reason error) error

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

func (h *Hub) NewBroadcast() *Broadcast

NewBroadcast gives the caller a new broadcast channel and kicks off the goroutine responsible for delivering broadcasted message to the connectors currently connected.

func (*Hub) Start

func (h *Hub) Start() error

Start instantiate the hub queues with current settings and kicks off the goroutine responsible for throttling the join queue.

func (*Hub) Stop

func (h *Hub) Stop(reason error) (error, []error)

Stop closes the join queue and disconnect all connectors from the hub. The throttling goroutine will also go down.

type OnCloser

type OnCloser interface {
	OnClose(error) error
}

OnCloser is the interface that requires a method to call upon disconnection of a connector.

type OnReadCloser

type OnReadCloser interface {
	OnCloser
	OnReader
}

OnReadCloser wraps the basic methods needed to be notified when data has been read or the connector has closed.

type OnReader

type OnReader interface {
	OnReadBinary([]byte) error
	OnReadText([]byte) error
}

OnReader is the interface that wraps the methods called when data is read from a connector.

type Welcomer

type Welcomer interface {
	Welcome() ([]byte, error)
}

Welcomer is the interface that wraps the method used to provide the initial messages to send to the connector on a successful join to the hub.

Directories

Path Synopsis
bin
ws
Package ws implements the Pivo/Websocket connector.
Package ws implements the Pivo/Websocket connector.

Jump to

Keyboard shortcuts

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