Documentation ¶
Index ¶
Constants ¶
const ( // DefaultTimeout is used in R/W macros when DefaultTimeout = 5 * time.Second )
Variables ¶
var ( // ErrTimeout is generated by timeout on a reader or writer ErrTimeout = errors.New("io: timeout") )
Functions ¶
This section is empty.
Types ¶
type CreationFunc ¶
type CreationFunc func() (io.ReadWriteCloser, error)
CreationFunc is a function which returns a new "connection" to something a closure should be used to encapsulate the variables and functions needed
func BackingOffTCPConnMaker ¶
func BackingOffTCPConnMaker(address string, timeout time.Duration) CreationFunc
BackingOffTCPConnMaker is a TCPConnMaker with hardcoded backoff parameters
func NetworkConnMaker ¶
func NetworkConnMaker(network string, address string, timeout time.Duration) CreationFunc
NetworkConnMaker builds the closure needed to satisfy the creationFunc interface
func SerialConnMaker ¶
func SerialConnMaker(cfg *serial.Config) CreationFunc
SerialConnMaker creates the closure for a new serial connection based on a config
func TCPConnMaker ¶
func TCPConnMaker(address string, timeout time.Duration) CreationFunc
TCPConnMaker wraps NetworkConnmaker with TCP as the network
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a communication pool which holds one or more connections to a device that will be closed if they are not in use, and re-opened as needed. it is concurrent safe. Pools must be created with NewPool.
func NewPool ¶
func NewPool(maxSize int, idleTimeout time.Duration, maker CreationFunc) *Pool
NewPool creates a new pool. At each interval of timeout, a connection may be freed if it is available. Calling Close terminates the background goroutine which closes idle connections and drains the pool as it is immediately if idleTimeout is zero, the pool never frees connections.
func (*Pool) Active ¶
Active returns the number of connections owned by the pool that are currently given out
func (*Pool) Close ¶
func (p *Pool) Close()
Close interrupts the background collection of idle connections if it is not called, the garbage collector can never free the pool and the background worker will never stop
func (*Pool) Destroy ¶
func (p *Pool) Destroy(rw io.ReadWriter)
Destroy immediately frees a communicator from the pool. This should be used instead of Put if the communicator has gone bad.
func (*Pool) Get ¶
func (p *Pool) Get() (io.ReadWriter, error)
Get retrieves a communicator from the channel, blocking until one is available if all are in use. It is guaranteed that there is no contestion for the ReadWriter. The consumer should not attempt to cast it to its concrete type and use it outside this interface.
When done with the communicator, return it with Put(), or discard it with Destroy() if it has become no good (e.g., all calls error).
If the error from Get is not nil, you must not return it to the pool.
func (*Pool) Put ¶
func (p *Pool) Put(rw io.ReadWriter)
Put restores a communicator to the pool. It may be reused, or will be be freed eventually by the pool. Junk communicators (ones that always error) should be Destroy()'d and not returned with Put.
func (*Pool) ReturnWithError ¶
func (p *Pool) ReturnWithError(rw io.ReadWriter, err error)
ReturnWithError calls Put if err == nil, else Destroy
type Terminator ¶
Terminator is a struct holding termination sequences and read/writers
func NewTerminator ¶
func NewTerminator(rw io.ReadWriter, Rx, Tx byte) Terminator
NewTerminator returns a wrapper around a Read/Writer that appends and strips termination bytes
type Timeout ¶
type Timeout struct {
// contains filtered or unexported fields
}
Timeout is a wrapper for IO ReadWriter which adds a timeout
func NewTimeout ¶
NewTimeout creates a new timeout wrapping a read/writer