github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/forwarding/endpoint.go (about)

     1  package forwarding
     2  
     3  import (
     4  	"net"
     5  )
     6  
     7  // Endpoint is a generic network connectivity interface that can represent both
     8  // listening or dialing. None of its methods should be considered safe for
     9  // concurrent invocation except Shutdown.
    10  type Endpoint interface {
    11  	// TransportErrors returns a channel that will be populated if an error
    12  	// occurs on the underlying transport. This is necessary for forwarding
    13  	// endpoints because (unlike synchronization endpoints) there's no
    14  	// simultaneous polling of both endpoints that will detect connection
    15  	// failure. By monitoring for transport errors separately, the forwarding
    16  	// loop can be cancelled immediately (instead of waiting for a dial
    17  	// operation to fail once the next connection is accepted). The endpoint
    18  	// should make no assumptions about whether this method will be called or
    19  	// whether the resulting channel will be read from. Callers should make no
    20  	// assumptions about whether or not the resulting channel will be populated.
    21  	// The returned channel may be nil if transport errors are not possible for
    22  	// the endpoint (e.g. with local endpoints).
    23  	TransportErrors() <-chan error
    24  
    25  	// Open should open a network connection for the endpoint. For listener
    26  	// (source) endpoints, this function should block until an incoming
    27  	// connection arrives. For dialer (destination) endpoints, this function
    28  	// should dial the underlying target.
    29  	Open() (net.Conn, error)
    30  
    31  	// Shutdown shuts down the endpoint. This function must unblock any pending
    32  	// Open call.
    33  	Shutdown() error
    34  }