pivo

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2015 License: BSD-2-Clause Imports: 3 Imported by: 3

README

Pivo's Hub of Sockets for Go

Pivo is the Go package for hub of sockets.

Getting started

Documentation
Installation

Install the Pivo library using the following go command.

$ go get gopkg.in/pivo.v2
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 IsBinaryMessage = 1

Marker for binary message type

View Source
const IsTextMessage = 0

Marker for text message type

View Source
const Version = "2.0.1"

The Pivo package version numbers

Variables

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

Error is thrown when the join queue is full.

View Source
var ErrPortBufferIsFull = errors.New("port buffer is full")

Error is thrown when a connector has its port buffer full.

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

func DefaultHub() *Hub

DefaultHub instantiate a new hub with default settings.

func (*Hub) Broadcast

func (h *Hub) Broadcast(m *Message)

Broadcast sends a message to all connectors on the hub.

func (*Hub) Join

func (h *Hub) Join(c Connector) error

Join adds the given connector to the hub.

func (*Hub) Leave

func (h *Hub) Leave(c Connector)

Leave disjoins the given connector from the hub.

func (*Hub) StartAndServe

func (h *Hub) StartAndServe(trigger interface{}) error

StartAndServe serves the hub until Stop() is requested.

func (*Hub) Stop

func (h *Hub) Stop()

Stop brings the hub down.

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

func BinaryMessage(from Connector, bin []byte) *Message

BinaryMessage formats a binary message and returns a pointer to it.

func TextMessage

func TextMessage(from Connector, text string) *Message

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

type OnBinaryReader interface {
	OnBinaryRead([]byte) error
}

OnBinaryReader is called when binary data is read from a connector.

type OnCloser

type OnCloser interface {
	OnClose(error) error
}

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

type OnHubBroadcaster

type OnHubBroadcaster interface {
	OnHubBroadcast(*Message) (Ports, error)
}

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

type OnHubJoiner interface {
	OnHubJoin(Connector) error
}

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

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 {
	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

type OnTextReader interface {
	OnTextRead(string) error
}

OnTextReader is called when text data is read from a connector.

type Port

type Port chan *Message

Port is a channel transporting a pointer to a Message.

type Ports

type Ports map[Connector]bool

Ports is a map of Connectors that have joined 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