bufpipe

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixedPipe

func FixedPipe(size int) (*PipeReader, *PipeWriter)

FixedPipe creates a synchronous in-memory pipe with a fixed-size buffer that has at least the specified size. It can be used to mimic a kernel provided fifo or socket which have an internal buffer and blocking I/O.

Reads will block until data is written. Writes will block when the internal buffer is filled.

It is safe to call Read and Write in parallel with each other or with Close. Parallel calls to Read and parallel calls to Write are also safe: the individual calls will be gated sequentially.

func Pipe

func Pipe() (*PipeReader, *PipeWriter)

Pipe creates a synchronous in-memory pipe with an unlimited buffer. If the input size is unknown a FixedPipe may be preferable.

Reads will block until data is written. Writes will never block.

It is safe to call Read and Write in parallel with each other or with Close. Parallel calls to Read and parallel calls to Write are also safe: the individual calls will be gated sequentially.

Types

type PipeReader

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

A PipeReader is the read half of a pipe.

func (*PipeReader) Close

func (r *PipeReader) Close() error

Close closes the reader; subsequent writes to the write half of the pipe will return the error io.ErrClosedPipe.

func (*PipeReader) CloseWithError

func (r *PipeReader) CloseWithError(err error) error

CloseWithError closes the reader; subsequent writes to the write half of the pipe will return the error err.

func (*PipeReader) Read

func (r *PipeReader) Read(data []byte) (n int, err error)

Read implements the standard Read interface: it reads data from the pipe, blocking until a writer arrives or the write end is closed. Closing the write end does not prevent reading buffered data. If the write end is closed with an error, that error is returned as err; otherwise err is io.EOF.

type PipeWriter

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

A PipeWriter is the write half of a pipe.

func (*PipeWriter) Close

func (w *PipeWriter) Close() error

Close closes the writer. Buffered data may still be read. Once the buffer is empty subsequent reads from the read half of the pipe will return no bytes and io.EOF.

func (*PipeWriter) CloseWithError

func (w *PipeWriter) CloseWithError(err error) error

CloseWithError closes the writer. Buffered data may still be read. Once the buffer is empty subsequent reads from the read half of the pipe will return no bytes and the error err, or io.EOF if err is nil.

CloseWithError always returns nil.

func (*PipeWriter) Write

func (w *PipeWriter) Write(data []byte) (n int, err error)

Write implements the standard Write interface: it writes data to the pipe, returning once the data is buffered or the read end is closed. When using a FixedPipe, Write may block until one or more readers have consumed some of the data. If the read end is closed with an error, that err is returned as err; otherwise err is io.ErrClosedPipe.

Jump to

Keyboard shortcuts

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