iopipes

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package iopipes provides implementation for a few new sets of pipes.

InfinitePipe provides a pipe that will grow indefinitely and never blocks. Because of the unbounded growth of the pipe, there should be an external syncronisation method to prevent what is effectively a memory leak.

DrainingPipe provides a pipe that will block writes once the internal buffer reaches or exceeds a specified capacity. However, it will still accept and write to the buffer the data that exceeds the buffer. Once the capacity has been reached, the DrainingPipe goes into draining mode and will only unblock when the entire buffer is read.

Index

Constants

This section is empty.

Variables

View Source
var ErrPipeFull = errors.New("the pipe buffer has reached capacity - pipe is in draining mode")

ErrPipeFull is returned from DrainingPipeWriter.Write if the pipes capacity has been reached.

Functions

func DrainingPipe

func DrainingPipe(capacity int, tell chan<- bool) (*DrainingPipeReader, *DrainingPipeWriter)

DrainingPipe is similar to io.Pipe() except that writes will always succeed (including the first write that overfills the buffer). Data will be added to an internal buffer that can grow bigger than the specified capacity. Additionally, you may supply a channel tell that will be told whenever the draining channel has been emptied, so that more bytes can be requested to be written.

This pipe kind is useful when implementing simple congestion control.

N.B. The Writer end of this pipe will not work with io.Copy because it returns an error when the pipe is full (but the pipe is still valid).

func InfinitePipe

func InfinitePipe() (*InfinitePipeReader, *InfinitePipeWriter)

InfinitePipe is similar to io.Pipe() except that writes will always succeed. Data will be added to an internal buffer that will always grow. Additionally, you may supply a channel tell that will be told whenever the Infinite channel has been emptied, so that more bytes can be requested to be written.

This pipe kind is useful when implementing simple congestion control.

Types

type DrainingPipeReader

type DrainingPipeReader struct {
	*DrainingPipeWriter
}

DrainingPipeReader is a reading side of an DrainingPipe, similar to io.PipeReader.

func (*DrainingPipeReader) Close

func (r *DrainingPipeReader) Close() error

Close the pipe reader

func (*DrainingPipeReader) Read

func (r *DrainingPipeReader) Read(p []byte) (int, error)

type DrainingPipeWriter

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

DrainingPipeWriter is a writing side of a DrainingPipe, similar to io.PipeWriter.

func (*DrainingPipeWriter) Close

func (w *DrainingPipeWriter) Close() error

Close will close the stream

func (*DrainingPipeWriter) Write

func (w *DrainingPipeWriter) Write(p []byte) (int, error)

type InfinitePipeReader

type InfinitePipeReader struct {
	*InfinitePipeWriter
}

InfinitePipeReader is a reading side of an InfinitePipe, similar to io.PipeReader.

func (*InfinitePipeReader) Close

func (r *InfinitePipeReader) Close() error

Close the pipe reader

func (*InfinitePipeReader) Read

func (r *InfinitePipeReader) Read(p []byte) (int, error)

type InfinitePipeWriter

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

InfinitePipeWriter is a writing side of an InfinitePipe, similar to io.PipeWriter.

func (*InfinitePipeWriter) Close

func (w *InfinitePipeWriter) Close() error

Close will close the stream

func (*InfinitePipeWriter) Write

func (w *InfinitePipeWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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