common

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleError

func HandleError(err error, errChan chan<- error)

HandleError handles the error by sending it to the errChan or logging it to standard error if errChan is nil.

Types

type Doner

type Doner interface {
	Done()
}

Doner is the interface for a sync.WaitGroup that can only call Done (signal the end).

type IdleTracker

type IdleTracker struct {
	IdleTimeout time.Duration
	// contains filtered or unexported fields
}

IdleTracker tracks activity and cancels a context when there is none during a whole IdleTimeout duration.

func (*IdleTracker) Start

func (t *IdleTracker) Start(ctx context.Context, cancel func(), d Doner)

Start starts the tracker. If the IdleTimeout is less than or equal to 0, there is no tracking to do and the call is a no-op, calling Done immediately on d. Otherwise it launches the tracking goroutine.

func (*IdleTracker) Touch

func (t *IdleTracker) Touch()

Touch notifies the tracker of activity.

func (*IdleTracker) TrackConn

func (t *IdleTracker) TrackConn(c net.Conn) net.Conn

TrackConn wraps the provided connection and returns a connection that notifies the tracker of activity on Read and Write.

type RetryServer

type RetryServer struct {
	// The Listener to use to listen for incoming connections.
	Listener net.Listener

	// The function to call in a goroutine to serve accepted connections.
	// On exit, the function should always close conn and call d.Done.
	Dispatch func(ctx context.Context, d Doner, conn net.Conn)

	// If non-nil, errors are reported on that channel. If the send would
	// block, the error is dropped. If it is nil, errors are logged.
	// It is the caller's responsibility to close the channel once the
	// server has exited.
	ErrChan chan<- error

	// If IdleTracker.IdleTimeout is greater than 0, terminates the
	// Server if there is no activity in that duration.
	IdleTracker IdleTracker
	// contains filtered or unexported fields
}

RetryServer encapsulates the common logic to all servers that listen for connections, retry on temporary errors after a delay, and dispatch a goroutine to handle connections.

func (*RetryServer) Serve

func (s *RetryServer) Serve(ctx context.Context) error

Serve starts accepting connections using RetryServer.Listener. It is a blocking call that always returns an error.

Jump to

Keyboard shortcuts

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