Documentation ¶
Index ¶
- Constants
- func ClearDeadline(c net.Conn) error
- func ClearReadDeadline(r SetReadDeadliner) error
- func ClearWriteDeadline(w SetWriteDeadliner) error
- func IsTemporary(err error) bool
- func IsTimeout(err error) bool
- func LimitListener(l net.Listener, n int) net.Listener
- func ReadWriteCloserWithRollingDeadlines(c net.Conn, rd time.Duration, wd time.Duration) io.ReadWriteCloser
- func ReadWriterWithRollingDeadlines(c net.Conn, rd time.Duration, wd time.Duration) io.ReadWriter
- func ReaderWithRollingDeadlines(c net.Conn, d time.Duration) io.Reader
- func RetryDial(ctx context.Context, dial DialFunc) (net.Conn, error)
- func RetryDialWithContext(ctx context.Context, dial DialWithContextFunc) (net.Conn, error)
- func RetryTemporary(f func() error) error
- func SetDeadline(c net.Conn, d time.Duration) error
- func SetDeadlineFromContext(ctx context.Context, c net.Conn, d time.Duration) error
- func SetReadDeadline(r SetReadDeadliner, d time.Duration) error
- func SetReadDeadlineFromContext(ctx context.Context, r SetReadDeadliner, d time.Duration) error
- func SetWriteDeadline(w SetWriteDeadliner, d time.Duration) error
- func SetWriteDeadlineFromContext(ctx context.Context, w SetWriteDeadliner, d time.Duration) error
- func WriterWithRollingDeadlines(c net.Conn, d time.Duration) io.Writer
- type Addrer
- type BinaryConn
- type BinaryConnReadWriteCloser
- type BinaryConnReader
- type BinaryConnWriter
- type ConnReadWriteCloser
- type ConnReader
- type ConnWriter
- type DialFunc
- type DialWithContextFunc
- type SetReadDeadliner
- type SetWriteDeadliner
Constants ¶
const MaxDialAttempts = 10
MaxDialAttempts is the maximum number of attempts RetryDial and RetryDialWithContext will make to dial a connection.
const MaxTemporaryAttempts = 5
MaxTemporaryAttempts is the maximum number of attempts RetryTemporary will make when encountering a temporary error.
const NilAddr = nilAddr(0)
NilAddr implements the net.Addr interface, and can be used to represent a nil address.
Variables ¶
This section is empty.
Functions ¶
func ClearDeadline ¶
ClearDeadline clears the read/write deadline.
func ClearReadDeadline ¶
func ClearReadDeadline(r SetReadDeadliner) error
ClearReadDeadline clears the read deadline.
func ClearWriteDeadline ¶
func ClearWriteDeadline(w SetWriteDeadliner) error
ClearWriteDeadline clears the write deadline.
func IsTemporary ¶
IsTemporary returns true if error is a temporary error
func LimitListener ¶
LimitListener returns a Listener based on l that accepts at most n simultaneous connections. It will panic if n is negative.
func ReadWriteCloserWithRollingDeadlines ¶
func ReadWriteCloserWithRollingDeadlines(c net.Conn, rd time.Duration, wd time.Duration) io.ReadWriteCloser
ReadWriteCloserWithRollingDeadlines wraps the connection c and returns an io.ReadWriteCloser. Calls to Read on the returned io.ReadWriter have an idle timeout duration of rd; calls to Write on the returned io.ReadWriter have an idle timeout duration of wd.
func ReadWriterWithRollingDeadlines ¶
ReadWriterWithRollingDeadlines wraps the connection c and returns an io.ReadWriter. Calls to Read on the returned io.ReadWriter have an idle timeout duration of rd; calls to Write on the returned io.ReadWriter have an idle timeout duration of wd.
func ReaderWithRollingDeadlines ¶
ReaderWithRollingDeadlines wraps the connection c and returns an io.Reader. Calls to Read on the returned io.Reader have an idle timeout duration d.
func RetryDial ¶
RetryDial attempts to dial a connection using the given dial function. If the dial fails, it will be retried with exponential back-off. The exponential back-off caps out at approximately 1 minute. This will try MaxDialAttempts times before abandoning the attempt; you can use the context to cancel the attempt sooner.
func RetryDialWithContext ¶
RetryDialWithContext attempts to dial a connection using the given dial function. If the dial fails, it will be retried with exponential back-off. The exponential back-off caps out at approximately 1 minute. This will try MaxDialAttempts times before abandoning the attempt; you can use the context to cancel the attempt sooner.
func RetryTemporary ¶
RetryTemporary executes the function f. If f returns a temporary error, it will be retried with exponential back-off. The exponential back-off caps out at approximately 1 second. This will try MaxTemporaryAttempts times before abandoning the attempt.
func SetDeadline ¶
SetDeadline sets the read/write deadline using the given duration.
func SetDeadlineFromContext ¶
SetDeadlineFromContext sets the read/write deadline to the minimum of the given context's deadline or the given duration. If the context does not have a deadline, or if the context's deadline is 0, then the duration is used.
func SetReadDeadline ¶
func SetReadDeadline(r SetReadDeadliner, d time.Duration) error
SetReadDeadline sets the read deadline using the given duration.
func SetReadDeadlineFromContext ¶
SetReadDeadlineFromContext sets the read deadline to the minimum of the given context's deadline or the given duration. If the context does not have a deadline, or if the context's deadline is 0, then the duration is used.
func SetWriteDeadline ¶
func SetWriteDeadline(w SetWriteDeadliner, d time.Duration) error
SetWriteDeadline sets the write deadline using the given duration.
func SetWriteDeadlineFromContext ¶
SetWriteDeadlineFromContext sets the write deadline to the minimum of the given context's deadline or the given duration. If the context does not have a deadline, or if the context's deadline is 0, then the duration is used.
Types ¶
type Addrer ¶
type Addrer interface { LocalAddr() net.Addr // LocalAddr returns the local network address. RemoteAddr() net.Addr // RemoteAddr returns the remote network address. }
Addrer is a subset of the net.Conn interface, only supporting methods for recovering the address.
type BinaryConn ¶
type BinaryConn interface { net.Conn binaryutil.ByteOrderer binaryutil.BasicReader binaryutil.BasicWriter }
BinaryConn is the interface encapsulating both the net.Conn and binaryutil.BinaryReadWriter interfaces.
func NewBinaryConn ¶
func NewBinaryConn(c net.Conn, e binary.ByteOrder) BinaryConn
NewBinaryConn wraps the given net.Conn and binary.ByteOrder as a BinaryConn.
type BinaryConnReadWriteCloser ¶
type BinaryConnReadWriteCloser interface { ConnReadWriteCloser binaryutil.ByteOrderer binaryutil.BasicReader binaryutil.BasicWriter }
BinaryConnReadWriteCloser is the interface encapsulating both the ConnReadWriteCloser and binaryutil.BinaryReadWriter interfaces.
func NewBinaryConnReadWriteCloser ¶
func NewBinaryConnReadWriteCloser(c ConnReadWriteCloser, e binary.ByteOrder) BinaryConnReadWriteCloser
NewBinaryConnReadWriteCloser wraps the given ConnReadWriteCloser and binary.ByteOrder as a BinaryConnReadWriteCloser.
type BinaryConnReader ¶
type BinaryConnReader interface { ConnReader binaryutil.ByteOrderer binaryutil.BasicReader }
BinaryConnReader is a subset of the BinaryConn interface, only supporting methods for reading data.
type BinaryConnWriter ¶
type BinaryConnWriter interface { ConnWriter binaryutil.ByteOrderer binaryutil.BasicWriter }
BinaryConnWriter is a subset of the BinaryConn interface, only supporting methods for writing data.
type ConnReadWriteCloser ¶
type ConnReadWriteCloser interface { net.Conn CloseRead() error // CloseRead shuts down the reading side of the connection. Most callers should just use Close. CloseWrite() error // CloseWrite shuts down the writing side of the connection. Most callers should just use Close. }
ConnReadWriteCloser extends the net.Conn interface to include separate CloseRead and CloseWrite methods.
type ConnReader ¶
type ConnReader interface { io.Reader SetReadDeadliner Addrer }
ConnReader is a subset of the net.Conn interface, only supporting methods for reading data.
type ConnWriter ¶
type ConnWriter interface { io.Writer SetWriteDeadliner Addrer }
ConnWriter is a subset of the net.Conn interface, only supporting methods for writing data.
type DialWithContextFunc ¶
DialWithContextFunc defines a function that can be used to dial a connection.
func DefaultTCPDialWithContextFunc ¶
func DefaultTCPDialWithContextFunc(host string, port int, lg log.Interface) DialWithContextFunc
DefaultTCPDialWithContextFunc returns a DialWithContextFunc that calls
net.Dial("tcp", host + ":" + port)
Logging messages will be sent to lg, if non-nil.
type SetReadDeadliner ¶
type SetReadDeadliner interface {
SetReadDeadline(t time.Time) error // SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.
}
SetReadDeadliner is the interface satisfied by the SetReadDeadline method.
type SetWriteDeadliner ¶
type SetWriteDeadliner interface {
SetWriteDeadline(t time.Time) error // SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.
}
SetWriteDeadliner is the interface satisfied by the SetWriteDeadline method.