streams

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxHeaderSize = 4096
)

Variables

View Source
var Localhost = MustResolveTcpAddress("tcp", "localhost:0")

Functions

func LogClose

func LogClose(closer io.Closer) error

LogClose will log when shutting wodn a connection

func MustResolveTcpAddress

func MustResolveTcpAddress(network, address string) *net.TCPAddr

func PipeData

func PipeData(down io.ReadWriteCloser, up io.ReadWriteCloser) error

PipeData does exactly what the name suggests, it pipes the data both ways -- from one reade to another writer and back. It closes the channel(s) on EOF or on errors.

func TryClose

func TryClose(closer io.Closer)

Try closing a connection and just report to log if it fails

Types

type BufferedInputConnection

type BufferedInputConnection struct {
	Connection
	Reader *bufio.Reader
}

BufferedInputConnection will buffer the incoming data (the "read") part of the io.ReadWriteCloser

func NewBufferedInputConnection

func NewBufferedInputConnection(c net.Conn) *BufferedInputConnection

func (BufferedInputConnection) Read

func (bf BufferedInputConnection) Read(p []byte) (n int, err error)

type Closed

type Closed interface {
	Closed() bool
}

Closed is an interface which defines if a method to check if a stream is closed or not

type Connection

type Connection interface {
	net.Conn
	Closed
}

Connection combines the net.Connection and Closed interfaces to provide the way to query if the connection has been closed or not.

type NamedConnection

type NamedConnection struct {
	Connection
	// contains filtered or unexported fields
}

NamedStream implements the io.ReadWriteCloser interface as well as fmt.Stringer. It allows the caller to setup a name for the stream which will be returned when outputing the stream with `%v`. It also makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewNamedConnection

func NewNamedConnection(wrapped net.Conn, name string) *NamedConnection

NewNamedStream will, unsurprisingly, create a new NamedStream with a given name

func (*NamedConnection) ReadFrom

func (ns *NamedConnection) ReadFrom(r io.Reader) (n int64, err error)

func (*NamedConnection) String

func (ns *NamedConnection) String() string

func (*NamedConnection) Unwrap

func (ns *NamedConnection) Unwrap() net.Conn

func (*NamedConnection) WriteTo

func (ns *NamedConnection) WriteTo(w io.Writer) (n int64, err error)

type NamedReader

type NamedReader struct {
	ReadCloserClosed
	// contains filtered or unexported fields
}

NamedReader implements the io.ReadCloser interface as well as fmt.Stringer. It allows the caller to setup a name for the stream which will be returned when outputing the stream with `%v`. It also makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewNamedReader

func NewNamedReader(wrapped io.ReadCloser, name string) *NamedReader

NewNamedReader will create a new NamedReader with the specified name.

func (*NamedReader) String

func (ns *NamedReader) String() string

String will return the "nice" name of the io.Reader -- tha name provided. If this reader wraps another io.Reader which implements the fmt.Stringer interface, it's name will be added at the end after the `->` sign, e.g. you will get `{this-name}->{wrapped-name}`. This allows you to elegantly see the hierarhy of the wrapped reader, if all of them have been wrapped into a NamedReader.

func (*NamedReader) Unwrap

func (ns *NamedReader) Unwrap() io.ReadCloser

Upwrap will return the underlying Reader.

func (*NamedReader) WriteTo

func (ns *NamedReader) WriteTo(w io.Writer) (n int64, err error)

WriteTo just implements the method from the reader

type NamedStream

type NamedStream struct {
	ReadWriteCloserClosed
	// contains filtered or unexported fields
}

NamedStream implements the io.ReadWriteCloser interface as well as fmt.Stringer. It allows the caller to setup a name for the stream which will be returned when outputing the stream with `%v`. It also makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewNamedStream

func NewNamedStream(wrapped io.ReadWriteCloser, name string) *NamedStream

NewNamedStream will, unsurprisingly, create a new NamedStream with a given name

func (*NamedStream) ReadFrom

func (ns *NamedStream) ReadFrom(r io.Reader) (n int64, err error)

func (*NamedStream) String

func (ns *NamedStream) String() string

func (*NamedStream) Unwrap

func (ns *NamedStream) Unwrap() io.ReadWriteCloser

func (*NamedStream) WriteTo

func (ns *NamedStream) WriteTo(w io.Writer) (n int64, err error)

type NamedWriter

type NamedWriter struct {
	WriteCloserClosed
	// contains filtered or unexported fields
}

NamedWriter implements the io.WriteCloser interface as well as fmt.Stringer. It allows the caller to setup a name for the stream which will be returned when outputing the stream with `%v`. It also makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewNamedWriter

func NewNamedWriter(wrapped io.WriteCloser, name string) *NamedWriter

NewNamedStream will, unsurprisingly, create a new NamedStream with a given name

func (*NamedWriter) ReadFrom

func (ns *NamedWriter) ReadFrom(r io.Reader) (n int64, err error)

func (*NamedWriter) String

func (ns *NamedWriter) String() string

func (*NamedWriter) Unwrap

func (ns *NamedWriter) Unwrap() io.WriteCloser

type PacketConnection added in v2.1.0

type PacketConnection interface {
	net.PacketConn
	Closed
}

type ReadCloserClosed

type ReadCloserClosed interface {
	io.ReadCloser
	Closed
}

type ReadWriteCloser

type ReadWriteCloser struct {
	ReadCloserClosed
	WriteCloserClosed
}

ReadWriteCloser converts one input stream and one output stream into a `ReadWriteCloser`.

func NewReadWriteCloser

func NewReadWriteCloser(reader io.ReadCloser, writer io.WriteCloser) *ReadWriteCloser

func (*ReadWriteCloser) Close

func (sc *ReadWriteCloser) Close() error

func (*ReadWriteCloser) Closed

func (sc *ReadWriteCloser) Closed() bool

Closed will return `true` if both reader and writer are closed

func (*ReadWriteCloser) ReadFrom

func (sc *ReadWriteCloser) ReadFrom(r io.Reader) (n int64, err error)

func (*ReadWriteCloser) WriteTo

func (sc *ReadWriteCloser) WriteTo(w io.Writer) (n int64, err error)

type ReadWriteCloserClosed

type ReadWriteCloserClosed interface {
	io.ReadWriteCloser
	Closed
}

type SafeConnection

type SafeConnection struct {
	net.Conn
	// contains filtered or unexported fields
}

SafeStream makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewSafeConnection

func NewSafeConnection(wrapped net.Conn) *SafeConnection

NewSafeStream will, create a new SafeStream with a given name. It *WILL NOT* create a new instance if the provided argument is already a SafeStream

func (*SafeConnection) Close

func (ns *SafeConnection) Close() error

Close will close the underlying stream. If the Close has already been called, it will do nothing

func (*SafeConnection) Closed

func (ns *SafeConnection) Closed() bool

Closed will return `true` if SafeStream.Close has been called at least once

func (*SafeConnection) ReadFrom

func (ns *SafeConnection) ReadFrom(r io.Reader) (n int64, err error)

func (*SafeConnection) Unwrap

func (ns *SafeConnection) Unwrap() net.Conn

Unwrap returns the embedded net.Conn

func (*SafeConnection) WriteTo

func (ns *SafeConnection) WriteTo(w io.Writer) (n int64, err error)

type SafeReader

type SafeReader struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

SafeReader implements the io.ReadCloser and makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewSafeReader

func NewSafeReader(wrapped io.ReadCloser) *SafeReader

func (*SafeReader) Close

func (ns *SafeReader) Close() error

Close will close the underlying stream. If the Close has already been called, it will do nothing

func (*SafeReader) Closed

func (ns *SafeReader) Closed() bool

Closed will return `true` if SafeReader.Close has been called at least once

func (*SafeReader) Unwrap

func (ns *SafeReader) Unwrap() io.ReadCloser

Unwrap returns the embedded io.ReadCloser

func (*SafeReader) WriteTo

func (ns *SafeReader) WriteTo(w io.Writer) (n int64, err error)

type SafeStream

type SafeStream struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

SafeStream makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewSafeStream

func NewSafeStream(wrapped io.ReadWriteCloser) *SafeStream

NewSafeStream will, create a new SafeStream with a given name. It *WILL NOT* create a new instance if the provided argument is already a SafeStream

func (*SafeStream) Close

func (ns *SafeStream) Close() error

Close will close the underlying stream. If the Close has already been called, it will do nothing

func (*SafeStream) Closed

func (ns *SafeStream) Closed() bool

Closed will return `true` if SafeStream.Close has been called at least once

func (*SafeStream) ReadFrom

func (ns *SafeStream) ReadFrom(r io.Reader) (n int64, err error)

func (*SafeStream) Unwrap

func (ns *SafeStream) Unwrap() io.ReadWriteCloser

Unwrap returns the embedded io.ReadWriteCloser

func (*SafeStream) WriteTo

func (ns *SafeStream) WriteTo(w io.Writer) (n int64, err error)

type SafeWriter

type SafeWriter struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

SafeWriter implements the io.WriteCloser and makes sure that `Close()` can be called safely multiple times. Calling `Close()` on a closed object will simply succeed without an error.

func NewSafeWriter

func NewSafeWriter(wrapped io.WriteCloser) *SafeWriter

func (*SafeWriter) Close

func (ns *SafeWriter) Close() error

Close will close the underlying stream. If the Close has already been called, it will do nothing

func (*SafeWriter) Closed

func (ns *SafeWriter) Closed() bool

Closed will return `true` if SafeWriter.Close has been called at least once

func (*SafeWriter) ReadFrom

func (ns *SafeWriter) ReadFrom(r io.Reader) (n int64, err error)

func (*SafeWriter) Unwrap

func (ns *SafeWriter) Unwrap() io.WriteCloser

Unwrap returns the embedded io.WriteCloser

type SimulatedConnection

type SimulatedConnection struct {
	ReadWriteCloserClosed
	// contains filtered or unexported fields
}

SimulatedConnection will simulate a net.Conn (implement its interfaces) while proxying calls to Read and Write to the undrlying input/output stream

func NewSimulatedConnection

func NewSimulatedConnection(wrapped io.ReadWriteCloser, local, remote net.Addr) *SimulatedConnection

func (*SimulatedConnection) LocalAddr

func (sc *SimulatedConnection) LocalAddr() net.Addr

func (*SimulatedConnection) ReadFrom

func (sc *SimulatedConnection) ReadFrom(r io.Reader) (n int64, err error)

func (*SimulatedConnection) RemoteAddr

func (sc *SimulatedConnection) RemoteAddr() net.Addr

func (*SimulatedConnection) SetDeadline

func (sc *SimulatedConnection) SetDeadline(t time.Time) error

func (*SimulatedConnection) SetReadDeadline

func (sc *SimulatedConnection) SetReadDeadline(t time.Time) error

func (*SimulatedConnection) SetWriteDeadline

func (sc *SimulatedConnection) SetWriteDeadline(t time.Time) error

func (*SimulatedConnection) Unwrap

func (sc *SimulatedConnection) Unwrap() io.ReadWriteCloser

func (*SimulatedConnection) WriteTo

func (sc *SimulatedConnection) WriteTo(w io.Writer) (n int64, err error)

type StreamWrappedConnection

type StreamWrappedConnection struct {
	ReadWriteCloserClosed
	// contains filtered or unexported fields
}

StreamWrappedConnection will wrap an input/output stream into a net.Conn interface while proxying the connection-specific calls to the underlying connection

func NewStreamConnection

func NewStreamConnection(wrapped io.ReadWriteCloser, underlying net.Conn) *StreamWrappedConnection

func (*StreamWrappedConnection) LocalAddr

func (sc *StreamWrappedConnection) LocalAddr() net.Addr

func (*StreamWrappedConnection) ReadFrom

func (sc *StreamWrappedConnection) ReadFrom(r io.Reader) (n int64, err error)

func (*StreamWrappedConnection) RemoteAddr

func (sc *StreamWrappedConnection) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*StreamWrappedConnection) SetDeadline

func (sc *StreamWrappedConnection) SetDeadline(t time.Time) error

func (*StreamWrappedConnection) SetReadDeadline

func (sc *StreamWrappedConnection) SetReadDeadline(t time.Time) error

func (*StreamWrappedConnection) SetWriteDeadline

func (sc *StreamWrappedConnection) SetWriteDeadline(t time.Time) error

func (*StreamWrappedConnection) Unwrap

func (*StreamWrappedConnection) WriteTo

func (sc *StreamWrappedConnection) WriteTo(w io.Writer) (n int64, err error)

type UnwrappedConnection

type UnwrappedConnection interface {
	Unwrap() net.Conn
}

type UnwrappedPacketConnection added in v2.1.0

type UnwrappedPacketConnection interface {
	Unwrap() net.PacketConn
}

type UnwrappedReadCloser

type UnwrappedReadCloser interface {
	Unwrap() io.ReadCloser
}

type UnwrappedReadWriteCloser

type UnwrappedReadWriteCloser interface {
	Unwrap() io.ReadWriteCloser
}

type UnwrappedWriteCloser

type UnwrappedWriteCloser interface {
	Unwrap() io.WriteCloser
}

type WebsocketTunnelConnection

type WebsocketTunnelConnection struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

WebsocketConnection implements a ReadWriteCloser over a websocket connection

func NewWebsocketTunnelConnection

func NewWebsocketTunnelConnection(conn *websocket.Conn) *WebsocketTunnelConnection

func (*WebsocketTunnelConnection) Close

func (wstc *WebsocketTunnelConnection) Close() error

func (*WebsocketTunnelConnection) Closed

func (wstc *WebsocketTunnelConnection) Closed() bool

func (*WebsocketTunnelConnection) LocalAddr

func (wstc *WebsocketTunnelConnection) LocalAddr() net.Addr

func (*WebsocketTunnelConnection) Read

func (wstc *WebsocketTunnelConnection) Read(p []byte) (int, error)

func (*WebsocketTunnelConnection) RemoteAddr

func (wstc *WebsocketTunnelConnection) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*WebsocketTunnelConnection) SetDeadline

func (wstc *WebsocketTunnelConnection) SetDeadline(t time.Time) error

func (*WebsocketTunnelConnection) SetReadDeadline

func (wstc *WebsocketTunnelConnection) SetReadDeadline(t time.Time) error

func (*WebsocketTunnelConnection) SetWriteDeadline

func (wstc *WebsocketTunnelConnection) SetWriteDeadline(t time.Time) error

func (*WebsocketTunnelConnection) Unwrap

func (wstc *WebsocketTunnelConnection) Unwrap() net.Conn

Unwrap returns the embedded net.Conn

func (*WebsocketTunnelConnection) Write

func (wstc *WebsocketTunnelConnection) Write(p []byte) (int, error)

Write will take a stream of bytes and send it over a websocket connection.

type WriteCloserClosed

type WriteCloserClosed interface {
	io.WriteCloser
	Closed
}

Directories

Path Synopsis
dns

Jump to

Keyboard shortcuts

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