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 ¶
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.
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
type InfinitePipeReader ¶
type InfinitePipeReader struct {
*InfinitePipeWriter
}
InfinitePipeReader is a reading side of an InfinitePipe, similar to io.PipeReader.
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