listener

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: ISC Imports: 10 Imported by: 0

README

listener - A TLS listener that can be stopped properly.

This implements a single TLS listening channel over an underlying TCP connection. Multiple clients can connect. A stop signal allows the server to disconnect the clients in an orderly way.

Documentation

Overview

A TLS listener that can be stopped properly

This implements a single TLS listening channel over an underlying TCP connection. Multiple clients can connect

A TLS listener that can be stopped properly

This implements a single TLS listening channel over an underlying TCP connection. Multiple clients can connect. A stop signal allows the server to disconnect the clients in an orderly way.

Index

Constants

View Source
const (
	Major   = "0"
	Minor   = "2"
	Patch   = "0"
	Version = Major + "." + Minor + "." + Patch
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(conn io.ReadWriteCloser, argument interface{})

the call back routine reads, writes and finally closes a connection

type ClientConnection

type ClientConnection struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

type to represent the connection as seen by the callback routine

Behaves as io.ReadWriteCloser and contains non-exported fields allow access to the underlying go routine handling the connection.

func (*ClientConnection) Close

func (conn *ClientConnection) Close() error

Close the Client connection

func (*ClientConnection) Read

func (conn *ClientConnection) Read(p []byte) (n int, err error)

read from the Client connection

This interfaces with the underlying listener to provide an orderly shutdown of the connection if the listener is stopped

func (*ClientConnection) Write

func (conn *ClientConnection) Write(p []byte) (n int, err error)

Write to Client connection

Just write to underlying TLS connection since writes are always allowed to complete. The stop occurs just prior to actual read from the TLS connection so that the remote gets a reply to its outstanding request before shutdown.

type Limiter

type Limiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

struct to hold the connection data

func NewBandwidthLimiter

func NewBandwidthLimiter(maximumCount int, bandwidthbps float64) (limiter *Limiter)

Create a new limiter

Current count is initially zero and the maximum is specified as a parameter.

func NewLimiter

func NewLimiter(maximumCount int) (limiter *Limiter)

Create a new limiter

Current count is initially zero and the maximum is specified as a parameter.

func (*Limiter) CurrentCount

func (limiter *Limiter) CurrentCount() int

Get current count

Read the current count, note that this may not be correct if other go routines are accessing the limiter. This is really intended so statistics/debugging display can look at a snapshot of limiter state.

func (*Limiter) Decrement

func (limiter *Limiter) Decrement() bool

Decrement count

Decrement the current count on a Limiter iff the currentCount is greater than zero.

func (*Limiter) Increment

func (limiter *Limiter) Increment() bool

Increment count

Increment the current count on a Limiter iff the currentCount is less than maximum.

func (*Limiter) RateLimit

func (limiter *Limiter) RateLimit(bytesRequested int) bool

rate limit

func (*Limiter) SetMaximum

func (limiter *Limiter) SetMaximum(maximumCount int) int

Set maximum count

Change the maximum count, returning the current maximum. This will not affect the current count in any way so reducing the maximum below the current will only serve to cause increment return false. Decrement will have to be used to bring the limiter down.

type Listener

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

struct to hold the connection data

func StartListening

func StartListening(tcpVersion string, listenAddress string, tlsConfiguration *tls.Config, limiter *Limiter, callback Callback, argument interface{}) (*Listener, error)

Start a new listener instance

Open a listening port and start a go routine to handle the actual accepts. Return a struct that can be used to shutdown the listener and all active connections in an orderly manner.

Note that tcp version must be either "tcp4" or "tcp6" and the listenAddress must be the a valid IPv4:port or IPv6:port

func (*Listener) ConnectionCount

func (listener *Listener) ConnectionCount() int32

Get the current number of connections

func (*Listener) StopListening

func (listener *Listener) StopListening() error

Stop the listener

Stops accepting new connections. Stops all active connections just before their next read (their writes complete so a to respond to their last request).

type MultiListener

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

structure to hold multi-listener instance

func NewMultiListener

func NewMultiListener(name string,
	listenAddresses []string,
	tlsConfiguration *tls.Config,
	limiter *Limiter,
	callback Callback) (*MultiListener, error)

Create a new multi-listener

This will fail if any bad host:port strings are given.

func (*MultiListener) ConnectionCount

func (server *MultiListener) ConnectionCount() int32

Total up the connections

func (*MultiListener) Start

func (server *MultiListener) Start(argument interface{})

Start the server

func (*MultiListener) Stop

func (server *MultiListener) Stop()

Stop the RPC server

Jump to

Keyboard shortcuts

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