stream

package
v0.0.0-...-df39993 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const MaxChunkSize int = 1024 * 16

MaxChunkSize is the maximum number of bytes to send in a single data message. According to https://github.com/grpc/grpc.github.io/issues/371 the optimal size is between 16KiB to 64KiB.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*ReadWriter
	// contains filtered or unexported fields
}

Conn wraps ReadWriter in a net.Conn interface.

func NewConn

func NewConn(rw *ReadWriter, src net.Addr, dst net.Addr) *Conn

NewConn creates a new Conn which transfers data via the provided ReadWriter.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr is the original source address of the client.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr is the address of the reverse tunnel node.

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

type ReadWriter

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

ReadWriter wraps a grpc source with an io.ReadWriter interface. All reads are consumed from [Source.Recv] and all writes and sent via [Source.Send].

func NewReadWriter

func NewReadWriter(source Source) (*ReadWriter, error)

NewReadWriter creates a new ReadWriter that leverages the provided source to retrieve data from and write data to.

func (*ReadWriter) Close

func (c *ReadWriter) Close() error

Close cleans up resources used by the stream.

func (*ReadWriter) Read

func (c *ReadWriter) Read(b []byte) (n int, err error)

Read returns data received from the stream source. Any data received from the stream that is not consumed will be buffered and returned on subsequent reads until there is none left. Only then will data be sourced from the stream again.

func (*ReadWriter) Write

func (c *ReadWriter) Write(b []byte) (int, error)

Write consumes all data provided and sends it on the grpc stream. To prevent exhausting the stream all sends on the stream are limited to be at most MaxChunkSize. If the data exceeds the MaxChunkSize it will be sent in batches.

type Source

type Source interface {
	Send([]byte) error
	Recv() ([]byte, error)
}

Source is a common interface for grpc client and server streams that transport opaque data.

Jump to

Keyboard shortcuts

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