channel_listener

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package channel_listener contains a listener that is able to pass arbitrary connections through a channel.

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
}

Listener is an implementation of a network listener that accepts connections from a channel. This allows for a flexible way to handle incoming connections.

func New

func New(in <-chan net.Conn, addr net.Addr) *Listener

New creates a new instance of Listener. net.Conn from the channel in are passed to Listener.Accept calls. addr is passed through to Listener.Addr.

func (*Listener) Accept

func (d *Listener) Accept() (net.Conn, error)

Accept waits for and returns the next connection from the channel. If the listener is closed, it returns the error used to close.

func (*Listener) Addr

func (d *Listener) Addr() net.Addr

Addr returns the address of the listener

func (*Listener) Close

func (d *Listener) Close() error

Close closes the listener and signals any goroutines in Listener.Accept to stop waiting. It calls Listener.CloseWithErr with nil.

func (*Listener) CloseWithErr

func (d *Listener) CloseWithErr(err error) error

CloseWithErr allows closing the listener with a specific error. This error will be returned by Listener.Accept when the listener is closed. Only the error from the first time this is called will be returned. If the passed err is nil, the error used to close is net.ErrClosed.

func (*Listener) Done

func (d *Listener) Done() <-chan struct{}

Done returns a channel that's closed when the listener is closed.

Jump to

Keyboard shortcuts

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