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) 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.
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) 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.