net2

package
v0.0.0-...-df3943b Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2014 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

net2 is a collection of functions meant to supplement the capabilities provided by the standard "net" package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLocalIPs

func GetLocalIPs() ([]*net.IP, error)

This returns the list of local ip addresses which other hosts can connect to (NOTE: Loopback ip is ignored).

Types

type ConnectionOptions

type ConnectionOptions struct {
	// The maximum number of connections that can be active per host at any
	// given time (A non-positive value indicates the number of connections
	// is unbounded).
	MaxActiveConnections int32

	// The maximum number of idle connections per host that are kept alive by
	// the connection pool.
	MaxIdleConnections uint32

	// The maximum amount of time an idle connection can alive (if specified).
	MaxIdleTime *time.Duration

	// Dial specifies the dial function for creating network connections.
	// If Dial is nil, net.Dial is used.
	Dial func(network string, address string) (net.Conn, error)

	// This specifies the now time function.  When the function is non-nil, the
	// connection pool will use the specified function instead of time.Now to
	// generate the current time.
	NowFunc func() time.Time
}

type ConnectionPool

type ConnectionPool interface {
	// This returns the number of active connections.
	NumActive() int32

	// This associates (network, address) to the connection pool; afterwhich,
	// the user can get connections to (network, address).
	Register(network string, address string) error

	// This dissociate (network, address) from the connection pool;
	// afterwhich, the user can no longer get connections to
	// (network, address).
	Unregister(network string, address string) error

	// This returns the list of registered (network, address) entries.
	ListRegistered() []NetworkAddress

	// This gets an active connection from the connection pool.  The connection
	// will remain active until one of the following is called:
	//  1. conn.ReleaseConnection()
	//  2. conn.DiscardConnection()
	//  3. pool.Release(conn)
	//  4. pool.Discard(conn)
	Get(network string, address string) (ManagedConn, error)

	// This releases an active connection back to the connection pool.
	Release(conn ManagedConn) error

	// This discards an active connection from the connection pool.
	Discard(conn ManagedConn) error

	// Enter the connection pool into lame duck mode.  The connection pool
	// will no longer return connections, and all idle connections are closed
	// immediately (including active connections that are released back to the
	// pool afterward).
	EnterLameDuckMode()
}

A generic interface for managed connection pool. All connection pool implementations must be threadsafe.

func NewMultiConnectionPool

func NewMultiConnectionPool(
	options ConnectionOptions,
	createPool func(ConnectionOptions) ConnectionPool) ConnectionPool

This returns a MultiConnectionPool, which manages multiple (network, address) entries. The connections to each (network, address) entry acts independently.

When createPool is nil, NewSimpleConnectionPool is used as default.

func NewSimpleConnectionPool

func NewSimpleConnectionPool(options ConnectionOptions) ConnectionPool

This returns a SimpleConnectionPool, where all connections are connected to (network, address)

type ManagedConn

type ManagedConn interface {
	net.Conn

	// This returns the original (network, address) entry used for creating
	// the connection.
	Key() NetworkAddress

	// This returns the underlying net.Conn implementation.
	RawConn() net.Conn

	// This returns the connection pool which owns this connection.
	Owner() ConnectionPool

	// This indictes a user is done with the connection and releases the
	// connection back to the connection pool.
	ReleaseConnection() error

	// This indicates the connection is an invalid state, and that the
	// connection should be discarded from the connection pool.
	DiscardConnection() error
}

A connection managed by a connection pool. NOTE: SetDeadline, SetReadDeadline and SetWriteDeadline are disabled for managed connections. (The deadlines are set by the connection pool).

func NewManagedConn

func NewManagedConn(
	network string,
	address string,
	conn net.Conn,
	pool ConnectionPool) ManagedConn

This creates a managed connection wrapper.

type ManagedConnImpl

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

A physical implementation of ManagedConn

func (*ManagedConnImpl) Close

func (c *ManagedConnImpl) Close() error

See net.Conn for documentation

func (*ManagedConnImpl) DiscardConnection

func (c *ManagedConnImpl) DiscardConnection() error

See ManagedConn for documentation.

func (*ManagedConnImpl) Key

See ManagedConn for documentation.

func (*ManagedConnImpl) LocalAddr

func (c *ManagedConnImpl) LocalAddr() net.Addr

See net.Conn for documentation

func (*ManagedConnImpl) Owner

func (c *ManagedConnImpl) Owner() ConnectionPool

See ManagedConn for documentation.

func (*ManagedConnImpl) RawConn

func (c *ManagedConnImpl) RawConn() net.Conn

See ManagedConn for documentation.

func (*ManagedConnImpl) Read

func (c *ManagedConnImpl) Read(b []byte) (n int, err error)

See net.Conn for documentation

func (*ManagedConnImpl) ReleaseConnection

func (c *ManagedConnImpl) ReleaseConnection() error

See ManagedConn for documentation.

func (*ManagedConnImpl) RemoteAddr

func (c *ManagedConnImpl) RemoteAddr() net.Addr

See net.Conn for documentation

func (*ManagedConnImpl) SetDeadline

func (c *ManagedConnImpl) SetDeadline(t time.Time) error

SetDeadline is disabled for managed connection (The deadline is set by the owner connection pool).

func (*ManagedConnImpl) SetReadDeadline

func (c *ManagedConnImpl) SetReadDeadline(t time.Time) error

SetReadDeadline is disabled for managed connection (The deadline is set by the owner connection pool).

func (*ManagedConnImpl) SetWriteDeadline

func (c *ManagedConnImpl) SetWriteDeadline(t time.Time) error

SetWriteDeadline is disabled for managed connection (The deadline is set by the owner connection pool).

func (*ManagedConnImpl) Write

func (c *ManagedConnImpl) Write(b []byte) (n int, err error)

See net.Conn for documentation

type MultiConnectionPool

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

A connection pool implementation that manages multiple (network, address) entries. The connections to each (network, address) entry acts independently. For example ("tcp", "localhost:11211") could act as memcache shard 0 and ("tcp", "localhost:11212") could act as memcache shard 1.

func (*MultiConnectionPool) Discard

func (p *MultiConnectionPool) Discard(conn ManagedConn) error

See ConnectionPool for documentation.

func (*MultiConnectionPool) EnterLameDuckMode

func (p *MultiConnectionPool) EnterLameDuckMode()

See ConnectionPool for documentation.

func (*MultiConnectionPool) Get

func (p *MultiConnectionPool) Get(
	network string,
	address string) (ManagedConn, error)

See ConnectionPool for documentation.

func (*MultiConnectionPool) ListRegistered

func (p *MultiConnectionPool) ListRegistered() []NetworkAddress

func (*MultiConnectionPool) NumActive

func (p *MultiConnectionPool) NumActive() int32

See ConnectionPool for documentation.

func (*MultiConnectionPool) Register

func (p *MultiConnectionPool) Register(network string, address string) error

See ConnectionPool for documentation.

func (*MultiConnectionPool) Release

func (p *MultiConnectionPool) Release(conn ManagedConn) error

See ConnectionPool for documentation.

func (*MultiConnectionPool) Unregister

func (p *MultiConnectionPool) Unregister(network string, address string) error

See ConnectionPool for documentation.

type NetworkAddress

type NetworkAddress struct {
	Network string
	Address string
}

Dial's arguments.

type SimpleConnectionPool

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

A connection pool implementation where all connections are connected to the same (network, address).

func (*SimpleConnectionPool) Discard

func (p *SimpleConnectionPool) Discard(conn ManagedConn) error

See ConnectionPool for documentation.

func (*SimpleConnectionPool) EnterLameDuckMode

func (p *SimpleConnectionPool) EnterLameDuckMode()

See ConnectionPool for documentation.

func (*SimpleConnectionPool) Get

func (p *SimpleConnectionPool) Get(
	network string,
	address string) (ManagedConn, error)

This gets an active connection from the connection pool. Note that network and address arguments are ignored (The connections with point to the network/address provided by the first Register call).

func (*SimpleConnectionPool) ListRegistered

func (p *SimpleConnectionPool) ListRegistered() []NetworkAddress

func (*SimpleConnectionPool) NumActive

func (p *SimpleConnectionPool) NumActive() int32

See ConnectionPool for documentation.

func (*SimpleConnectionPool) NumIdle

func (p *SimpleConnectionPool) NumIdle() int

This returns the number of alive idle connections. This method is not part of ConnectionPool's API. It is used only for testing.

func (*SimpleConnectionPool) Register

func (p *SimpleConnectionPool) Register(network string, address string) error

SimpleConnectionPool can only register a single (network, address) entry. Register should be call before any Get calls.

func (*SimpleConnectionPool) Release

func (p *SimpleConnectionPool) Release(conn ManagedConn) error

See ConnectionPool for documentation.

func (*SimpleConnectionPool) Unregister

func (p *SimpleConnectionPool) Unregister(
	network string,
	address string) error

SimpleConnectionPool does not support Unregister.

Directories

Path Synopsis
http2 is a collection of functions meant to supplement the capabilities provided by the standard "net/http" package.
http2 is a collection of functions meant to supplement the capabilities provided by the standard "net/http" package.

Jump to

Keyboard shortcuts

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