chunk

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package chunk provides a high level chunking client. A chunk is defined as a defined amount of data. A chunk client will work with *uds.Client, *uds.Conn object for chunking in clients and servers.

The high level RPC clients in all packages use chunk underneath.

A chunk client simply writes a variadic int to indicate the next message size to be written and then writes the message. On a read call it reads the int indicating the size and then reads in that amount of buffer.

The format is:

[varint][data chunk]

The chunk client can set a maximum message size.

If a read error occurs, the chunk client will close the connection. Read errors should only happen if the maximum message size is exceeded or io.EOF to indicate the socket is closed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a wrapper around an *uds.Client or *uds.Server that can send data chunks.

func New

func New(rwc io.ReadWriteCloser, options ...Option) (*Client, error)

New is the constructor for Client. rwc must be a *uds.Client or *uds.Conn.

func (*Client) Close added in v1.0.7

func (c *Client) Close() error

Close closes the underlying io.ReadWriteCloser.

func (*Client) ClosedSignal added in v1.1.1

func (c *Client) ClosedSignal() chan struct{}

ClosedSignal returns a channel that will be closed when this Client becomes closed.

func (*Client) Read

func (c *Client) Read() (*[]byte, error)

Read reads the next message from the socket. Any error closes the client.

func (*Client) Recycle

func (c *Client) Recycle(b *[]byte)

Recycle recycles a *[]byte. This should only be done when the Buffer is no longer used.

func (*Client) Write

func (c *Client) Write(b []byte) error

Write writes b as a chunk into the socket. Any error closes the client.

type Option

type Option func(c *Client)

Option is an optional argument to New.

func MaxSize

func MaxSize(size int64) Option

MaxSize is the maximum size a read message is allowed to be. If a message is larger than this, Next() will fail and the underlying connection will be closed.

func SharedPool

func SharedPool(pool *Pool) Option

SharedPool allows the use of a shared pool of buffers between Client instead of a pool per client. This is useful when clients are short lived and have similar message sizes. Client will panic if the pool does not return a *[]byte object.

type Pool added in v1.1.0

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

Pool is a memory pool for buffers.

func NewPool added in v1.1.0

func NewPool(cap int) *Pool

NewPool is the constructor for Pool. cap is capacity of an internal free list before using a sync.Pool.

func (*Pool) Get added in v1.1.0

func (p *Pool) Get() *[]byte

Get gets some buffer out of the pool.

func (*Pool) Put added in v1.1.0

func (p *Pool) Put(b *[]byte)

Put puts buffer back into the pool.

Directories

Path Synopsis
rpc
Package rpc provides an RPC service for non-specific []byte in and []byte out data.
Package rpc provides an RPC service for non-specific []byte in and []byte out data.

Jump to

Keyboard shortcuts

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