Documentation ¶
Index ¶
Constants ¶
const DefaultJobQueueSize = 10
DefaultJobQueueSize specifies the size of the job queue created to support IO operations on the Conn.
const DefaultRetryMax = time.Minute
DefaultRetryMax is the default maximum amount of time the client will wait to reconnect to a remote host if the connection drops.
const DefaultRetryMin = time.Second
DefaultRetryMin is the default minimum amount of time the client will wait to reconnect to a remote host if the connection drops.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configurator ¶
Configurator is a function that modifies a Conn structure during initialization.
func Address ¶
func Address(address string) Configurator
Address changes the network address used by a .
func DialTimeout ¶
func DialTimeout(duration time.Duration) Configurator
DialTimeout specifies the timeout to use when establishing the connection to the remote host.
func Logger ¶
func Logger(printer Printer) Configurator
Logger specifies an optional logger to invoke to log warning messages.
func RetryMax ¶
func RetryMax(duration time.Duration) Configurator
RetryMax controls the maximum amount of time a Conn will wait between connection attempts to the remote host.
func RetryMin ¶
func RetryMin(duration time.Duration) Configurator
RetryMin controls the minimum amount of time a Conn will wait between connection attempts to the remote host.
type Conn ¶
Conn wraps a net.Conn, providing a pseudo-persistent network connection.
func New ¶
func New(setters ...Configurator) (*Conn, error)
New returns a Conn structure that wraps the net.Conn connection, and attempts to provide a pseudo-persistent connection to a remote host.
package main import ( "log" "os" "time" "github.com/karrick/goperconn" ) func main() { printer := log.New(os.Stderr, "WARNING: ", 0) // NOTE: Address is required, but all other parameters have defaults. conn, err := goperconn.New(goperconn.Address("echo-server.example.com:7"), goperconn.DialTimeout(5*time.Second), goperconn.Logger(printer), goperconn.RetryMin(time.Second), goperconn.RetryMax(30*time.Second)) if err != nil { log.Fatal(err) } // later ... _, err = conn.Write([]byte("hello, world")) if err != nil { log.Fatal(err) } buf := make([]byte, 512) _, err = conn.Read(buf) if err != nil { log.Fatal(err) } }
type ErrClosedConnection ¶
type ErrClosedConnection struct{}
ErrClosedConnection is returned when I/O operation attempted on closed connection.
func (ErrClosedConnection) Error ¶
func (e ErrClosedConnection) Error() string
type ErrDialFailure ¶
ErrDialFailure is optionally sent to the configured warning hookback when net.DialTimeout fails. The library will continue to attempt to reestablish the connection, but this error is useful for client application logging purposes.
func (ErrDialFailure) Error ¶
func (e ErrDialFailure) Error() string
type ErrIOError ¶
type ErrIOError struct { Op opcode Err error }
ErrIOError is optionally sent to the configured warning hookback when an I/O operation fails. The library will close and attempt to reestablish the connection, but this error is useful for client application logging purposes.
func (ErrIOError) Error ¶
func (e ErrIOError) Error() string