pipe

package
v0.0.0-...-9ec6d29 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pipe implements a shared memory ring buffer on which a single reader and a single writer can operate (read/write) concurrently. The ring buffer allows for data of different sizes to be written, and preserves the boundary of the written data.

Example usage is as follows:

wb := t.Push(20)
// Write data to wb.
t.Flush()

rb := r.Pull()
// Do something with data in rb.
t.Flush()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rx

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

Rx is the receive side of the shared memory ring buffer.

func (*Rx) Abort

func (r *Rx) Abort()

Abort unpulls any pulled buffers.

func (*Rx) Bytes

func (r *Rx) Bytes() []byte

Bytes returns the byte slice on which the pipe operates.

func (*Rx) Flush

func (r *Rx) Flush()

Flush tells the transmitter that all buffers pulled since the last Flush() have been used, so the transmitter is free to used their slots for further transmission.

func (*Rx) Init

func (r *Rx) Init(b []byte)

Init initializes the receive end of the pipe. In the initial state, the next slot to be inspected is the very first one.

func (*Rx) Pull

func (r *Rx) Pull() []byte

Pull reads the next buffer from the pipe, returning nil if there isn't one currently available.

The returned slice is available until Flush() is next called. After that, it must not be touched.

type Tx

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

Tx is the transmit side of the shared memory ring buffer.

func (*Tx) Abort

func (t *Tx) Abort()

Abort causes all Push() calls since the last Flush() to be forgotten and therefore they will not be made visible to the receiver.

func (*Tx) Bytes

func (t *Tx) Bytes() []byte

Bytes returns the byte slice on which the pipe operates.

func (*Tx) Capacity

func (t *Tx) Capacity(recordSize uint64) uint64

Capacity determines how many records of the given size can be written to the pipe before it fills up.

func (*Tx) Flush

func (t *Tx) Flush()

Flush causes all buffers pushed since the last Flush() [or Abort(), whichever is the most recent] to be made visible to the receiver.

func (*Tx) Init

func (t *Tx) Init(b []byte)

Init initializes the transmit end of the pipe. In the initial state, the next slot to be written is the very first one, and the transmitter has the whole ring buffer available to it.

func (*Tx) Push

func (t *Tx) Push(payloadSize uint64) []byte

Push reserves "payloadSize" bytes for transmission in the pipe. The caller populates the returned slice with the data to be transferred and enventually calls Flush() to make the data visible to the reader, or Abort() to make the pipe forget all Push() calls since the last Flush().

The returned slice is available until Flush() or Abort() is next called. After that, it must not be touched.

Jump to

Keyboard shortcuts

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