netadaptor

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package netadaptor implements an adaptor from transport.AuthenticatedListener to net.Listener.

In contrast to transport.AuthenticatedListener, net.Listener is commonly expected (e.g. by net/http.Server.Serve), to return errors that fulfill the Temporary interface:

interface Temporary { Temporary() bool }

Common behavior of packages consuming net.Listener is to return from the serve-loop if an error returned by Accept is not Temporary, i.e., does not implement the interface or is !net.Error.Temporary().

The zrepl transport infrastructure was written with the idea that Accept() may return any kind of error, and the consumer would just log the error and continue calling Accept(). We have to adapt these listeners' behavior to the expectations of net/http.Server.

Hence, Listener does not return an error at all but blocks the caller of Accept() until we get a (successfully authenticated) connection without errors from the transport. Accept errors returned from the transport are logged as errors to the logger passed on initialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

func New

func New(authListener transport.AuthenticatedListener, l Logger) *Listener

Consume the given authListener and wrap it as a *Listener, which implements net.Listener. The returned net.Listener must be closed. The wrapped authListener is closed when the returned net.Listener is closed.

func (Listener) Accept

func (a Listener) Accept() (net.Conn, error)

The returned net.Conn is guaranteed to be *transport.AuthConn, i.e., the type of connection returned by the wrapped transport.AuthenticatedListener.

func (Listener) Addr

func (a Listener) Addr() net.Addr

func (Listener) Close

func (a Listener) Close() error

type Logger

type Logger = logger.Logger

Jump to

Keyboard shortcuts

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