reaper

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 7 Imported by: 10

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

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("IOActivityTimeout: closed connection")

ErrClosed is returned if IOActivityTimeout is called on a closed connection

Functions

func IOActivityTimeout

func IOActivityTimeout(c net.Conn, enable bool) (success bool, err error)

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

func StartTimer(c net.Conn, to time.Duration, afterfunc func(wrapped net.Conn))

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.

func StopTimer

func StopTimer(c net.Conn)

StopTimer stops any timer on the connection. StopTimer is go-routine safe.

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.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (rc net.Conn, err error)

Dial implements a Dial function like *net.Dialer

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (rc net.Conn, err error)

DialContext implements a DialContext function like *net.Dialer

Jump to

Keyboard shortcuts

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