channel

package module
v0.0.0-...-788c3aa Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2015 License: BSD-3-Clause Imports: 5 Imported by: 0

README

go-channel

Auto-balancing connection to multiple endpoints

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterURLHandler

func RegisterURLHandler(schema string, uh URLHandler)

Register a given handler for the specified URL pattern.

Types

type Channel

type Channel interface {
	net.Conn

	// Delay until either we have at least 1 backend or until the deadline
	// has expired. In case the deadline expires, an error is returned.
	WaitForNonEmpty(deadline time.Duration) error

	// Suggest to the channel to pick the next backend. This can be used
	// for load balancing or other reasons. There's no guarantee that the
	// backend will actually change though.
	NextBackend()

	// Total number of backends currently connected.
	NumBackends() uint64

	// List of all channels contained in this one. Can be useful to e.g.
	// perform broadcast RPCs.
	GetAllSubchannels() []Channel
}

Channels are essentially read/write/close interfaces with an additional option to force the channel to have at least one backend, and to switch to a different backend (which may or may not do something).

func ChannelFromString

func ChannelFromString(dest string, timeout time.Duration) (
	c Channel, err error)

Connect to the destintation specified in "dest" (which should be an URL).

func ChannelFromURL

func ChannelFromURL(u *url.URL, timeout time.Duration) (
	c Channel, err error)

Connect to the destination specified in "dest". A handler for the URL schema must be registered.

func NewChannelFromSocket

func NewChannelFromSocket(connection net.Conn, timeout time.Duration) Channel

Encapsulate the specified socket in a channel.

func NewSocketChannel

func NewSocketChannel(proto, dest string, timeout time.Duration) (ch Channel, err error)

Create a new socket channel for connecting to "dest". If "timeout" is greater than 0, set deadlines on all operations to the current time plus "timeout".

func NewTCPChannel

func NewTCPChannel(dest *url.URL, timeout time.Duration) (ch Channel, err error)

Create a new TCP channel for connecting to "dest". If "timeout" is greater than 0, set deadlines on all operations to the current time plus "timeout".

func NewUDPChannel

func NewUDPChannel(dest *url.URL, timeout time.Duration) (ch Channel, err error)

Create a new UDP channel for connecting to "dest". If "timeout" is greater than 0, set deadlines on all operations to the current time plus "timeout".

type SocketChannel

type SocketChannel struct {
	// contains filtered or unexported fields
}

A TCP channel is a channel over a simple TCP connection with just one peer.

func (*SocketChannel) Close

func (t *SocketChannel) Close() error

Closing a Socket channel closes the underlying Socket socket.

func (*SocketChannel) GetAllSubchannels

func (t *SocketChannel) GetAllSubchannels() []Channel

Sockets only have a single backend, so the largest subset of channels making up this channel is this channel itself.

func (*SocketChannel) LocalAddr

func (t *SocketChannel) LocalAddr() net.Addr

Local address is whatever the connection feels like.

func (*SocketChannel) NextBackend

func (*SocketChannel) NextBackend()

On single-destination Socket connections, switching channels is a no-op.

func (*SocketChannel) NumBackends

func (s *SocketChannel) NumBackends() uint64

Sockets only have a single backend.

func (*SocketChannel) Read

func (t *SocketChannel) Read(p []byte) (n int, err error)

Reading from a Socket channel is basically just reading from the underlying Socket connection.

func (*SocketChannel) RemoteAddr

func (t *SocketChannel) RemoteAddr() net.Addr

Remote address is whatever the connection thinks it is.

func (*SocketChannel) SetDeadline

func (s *SocketChannel) SetDeadline(t time.Time) error

Set the deadline for reading and writing and stop automated deadline management.

func (*SocketChannel) SetReadDeadline

func (s *SocketChannel) SetReadDeadline(t time.Time) error

Set the deadline for reading and stop automated deadline management.

func (*SocketChannel) SetWriteDeadline

func (s *SocketChannel) SetWriteDeadline(t time.Time) error

Set the deadline for writing and stop automated deadline management.

func (*SocketChannel) WaitForNonEmpty

func (*SocketChannel) WaitForNonEmpty(unused time.Duration) error

Socket channels are connected as soon as the constructor returns.

func (*SocketChannel) Write

func (t *SocketChannel) Write(p []byte) (n int, err error)

Writing to a Socket channel is slightly more involved than reading from it. If the channel was closed, it must be reestablished.

type URLHandler

type URLHandler func(*url.URL, time.Duration) (Channel, error)

Function creating a channel from the given URL.

Jump to

Keyboard shortcuts

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