Documentation
¶
Overview ¶
Package reaper implements an IOActivityTimeout for a net.Conn by having a reaper go-routine monitoring connections for IO activity and close connections which fail to show activity.
It supports net.Conn objects directly and if they are wrapped in *tls.Conn
Index ¶
- Variables
- func IOActivityTimeout(c net.Conn, enable bool) (success bool, err error)
- func NewIOActivityTimeoutListener(orig net.Listener, timeout, reaperInterval time.Duration) (l net.Listener)
- func StartTimer(c net.Conn, to time.Duration, afterfunc func(wrapped net.Conn))
- func StopTimer(c net.Conn)
- type Dialer
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("IOActivityTimeout: closed connection")
ErrClosed is returned if IOActivityTimeout is called on a closed connection
Functions ¶
func IOActivityTimeout ¶
IOActivityTimeout lets you toggle whether IOActivityTimeout is enabled for a net.Conn. It will work even if the net.Conn is wrapped as a *tls.Conn, but to do this requires an unsafe conversion relying on the underlying net.Conn being the first member of the tls.Conn struct. This is sadly necessary since crypto/tls.Conn doesn't expose the underlying net.Conn. Go 1.8 supports getting to the underlying net.Conn through ClientHelloInfo. That is however too late for this purpose.
func NewIOActivityTimeoutListener ¶
func NewIOActivityTimeoutListener(orig net.Listener, timeout, reaperInterval time.Duration) (l net.Listener)
NewIOActivityTimeoutListener wraps net.Listener with IOActivityTimeout functionality, so the accepted connections can use IOActivityTimeout() to enable it. The returned listener will not enable IOActivityTimeout per default. A reaperInterval of zero disables reaper monitoring
func StartTimer ¶
StartTimer allows to put a timer on a Conn, and via time.AfterFunc have a function called. The provided afterfunc is called with the net.Conn created by this package - if any. Meaning, that even if wrapped with TLS, calling Close() will close the underlying connection regardless of TLS state.
Types ¶
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer implements Dial* functions for connections which can be monitored by a IOActivityTimeout reaper
func NewIOActivityTimeoutDialer ¶
func NewIOActivityTimeoutDialer(orig *net.Dialer, timeout, reaperInterval time.Duration, enableByDefault bool) (d *Dialer)
NewIOActivityTimeoutDialer wraps a *net.Dialer with potential IOActivityTimeout monitoring. - only enabled by default if requested.