Documentation ¶
Index ¶
- Constants
- Variables
- func LogClose(closer io.Closer) error
- func MustResolveTcpAddress(network, address string) *net.TCPAddr
- func PipeData(down io.ReadWriteCloser, up io.ReadWriteCloser) error
- func TryClose(closer io.Closer)
- type BufferedInputConnection
- type Closed
- type Connection
- type NamedConnection
- type NamedReader
- type NamedStream
- type NamedWriter
- type PacketConnection
- type ReadCloserClosed
- type ReadWriteCloser
- type ReadWriteCloserClosed
- type SafeConnection
- type SafeReader
- type SafeStream
- type SafeWriter
- type SimulatedConnection
- func (sc *SimulatedConnection) LocalAddr() net.Addr
- func (sc *SimulatedConnection) ReadFrom(r io.Reader) (n int64, err error)
- func (sc *SimulatedConnection) RemoteAddr() net.Addr
- func (sc *SimulatedConnection) SetDeadline(t time.Time) error
- func (sc *SimulatedConnection) SetReadDeadline(t time.Time) error
- func (sc *SimulatedConnection) SetWriteDeadline(t time.Time) error
- func (sc *SimulatedConnection) Unwrap() io.ReadWriteCloser
- func (sc *SimulatedConnection) WriteTo(w io.Writer) (n int64, err error)
- type StreamWrappedConnection
- func (sc *StreamWrappedConnection) LocalAddr() net.Addr
- func (sc *StreamWrappedConnection) ReadFrom(r io.Reader) (n int64, err error)
- func (sc *StreamWrappedConnection) RemoteAddr() net.Addr
- func (sc *StreamWrappedConnection) SetDeadline(t time.Time) error
- func (sc *StreamWrappedConnection) SetReadDeadline(t time.Time) error
- func (sc *StreamWrappedConnection) SetWriteDeadline(t time.Time) error
- func (sc *StreamWrappedConnection) Unwrap() io.ReadWriteCloser
- func (sc *StreamWrappedConnection) WriteTo(w io.Writer) (n int64, err error)
- type UnwrappedConnection
- type UnwrappedPacketConnection
- type UnwrappedReadCloser
- type UnwrappedReadWriteCloser
- type UnwrappedWriteCloser
- type WebsocketTunnelConnection
- func (wstc *WebsocketTunnelConnection) Close() error
- func (wstc *WebsocketTunnelConnection) Closed() bool
- func (wstc *WebsocketTunnelConnection) LocalAddr() net.Addr
- func (wstc *WebsocketTunnelConnection) Read(p []byte) (int, error)
- func (wstc *WebsocketTunnelConnection) RemoteAddr() net.Addr
- func (wstc *WebsocketTunnelConnection) SetDeadline(t time.Time) error
- func (wstc *WebsocketTunnelConnection) SetReadDeadline(t time.Time) error
- func (wstc *WebsocketTunnelConnection) SetWriteDeadline(t time.Time) error
- func (wstc *WebsocketTunnelConnection) Unwrap() net.Conn
- func (wstc *WebsocketTunnelConnection) Write(p []byte) (int, error)
- type WriteCloserClosed
Constants ¶
const (
MaxHeaderSize = 4096
)
Variables ¶
var Localhost = MustResolveTcpAddress("tcp", "localhost:0")
Functions ¶
func MustResolveTcpAddress ¶
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.
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
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 ¶
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
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.
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) String ¶
func (ns *NamedStream) String() string
func (*NamedStream) Unwrap ¶
func (ns *NamedStream) Unwrap() io.ReadWriteCloser
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) 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
type ReadWriteCloserClosed ¶
type ReadWriteCloserClosed interface { io.ReadWriteCloser Closed }
type SafeConnection ¶
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
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
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) Unwrap ¶
func (ns *SafeStream) Unwrap() io.ReadWriteCloser
Unwrap returns the embedded io.ReadWriteCloser
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) 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
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 (sc *StreamWrappedConnection) Unwrap() io.ReadWriteCloser
type UnwrappedConnection ¶
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 ¶
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
type WriteCloserClosed ¶
type WriteCloserClosed interface { io.WriteCloser Closed }