Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
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 ¶
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.
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.