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 ¶
- type Rx
- func (r *Rx) Abort()
- func (r *Rx) Bytes() []byte
- func (r *Rx) Flush()
- func (r *Rx) Init(b []byte)
- func (r *Rx) Pull() []byte
- func (r *Rx) StateFields() []string
- func (r *Rx) StateLoad(ctx context.Context, stateSourceObject state.Source)
- func (r *Rx) StateSave(stateSinkObject state.Sink)
- func (r *Rx) StateTypeName() string
- type Tx
- func (t *Tx) Abort()
- func (t *Tx) Bytes() []byte
- func (t *Tx) Capacity(recordSize uint64) uint64
- func (t *Tx) Flush()
- func (t *Tx) Init(b []byte)
- func (t *Tx) Push(payloadSize uint64) []byte
- func (t *Tx) StateFields() []string
- func (t *Tx) StateLoad(ctx context.Context, stateSourceObject state.Source)
- func (t *Tx) StateSave(stateSinkObject state.Sink)
- func (t *Tx) StateTypeName() string
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.
+stateify savable
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 ¶
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 ¶
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.
func (*Rx) StateFields ¶
func (*Rx) StateTypeName ¶
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is the transmit side of the shared memory ring buffer.
+stateify savable
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) Capacity ¶
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 ¶
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 ¶
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.