pipe

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package pipe provides an in-memory implementation of a unidirectional pipe.

The goal of this pipe is to emulate the pipe syscall in all of its edge cases and guarantees of atomic IO.

Index

Constants

View Source
const DefaultPipeSize = 65536

DefaultPipeSize is the system-wide default size of a pipe in bytes.

Variables

This section is empty.

Functions

func NewConnectedPipe

func NewConnectedPipe(ctx context.Context, sizeBytes int, atomicIOBytes int) (*fs.File, *fs.File)

NewConnectedPipe initializes a pipe and returns a pair of objects (which implement kio.File) representing the read and write ends of the pipe. A pipe created by this function becomes invalid as soon as either the read or write end is closed, and errors on subsequent operations on either end. Pipes for pipe(2) and pipe2(2) are generally created this way.

func NewInodeOperations

func NewInodeOperations(base fs.InodeOperations, p *Pipe) fs.InodeOperations

NewInodeOperations creates a new pipe fs.InodeOperations.

Types

type Buffer

type Buffer struct {
	ilist.Entry
	// contains filtered or unexported fields
}

Buffer encapsulates a queueable byte buffer that can easily be truncated. It is designed only for use with pipes.

type Pipe

type Pipe struct {
	waiter.Queue `state:"nosave"`
	// contains filtered or unexported fields
}

Pipe is an encapsulation of a platform-independent pipe. It manages a buffered byte queue shared between a reader/writer pair.

func NewPipe

func NewPipe(ctx context.Context, isNamed bool, sizeBytes, atomicIOBytes int) *Pipe

NewPipe initializes and returns a pipe. A pipe created by this function is persistent, and will remain valid even without any open fds to it. Named pipes for mknod(2) are created via this function. Note that the implementation of blocking semantics for opening the read and write ends of a named pipe are left to filesystems.

func (*Pipe) HasReaders

func (p *Pipe) HasReaders() bool

HasReaders returns whether the pipe has any active readers.

func (*Pipe) HasWriters

func (p *Pipe) HasWriters() bool

HasWriters returns whether the pipe has any active writers.

func (*Pipe) ROpen

func (p *Pipe) ROpen(ctx context.Context) *fs.File

ROpen opens the pipe for reading.

func (*Pipe) RWOpen

func (p *Pipe) RWOpen(ctx context.Context) *fs.File

RWOpen opens the pipe for both reading and writing.

func (*Pipe) WOpen

func (p *Pipe) WOpen(ctx context.Context) *fs.File

WOpen opens the pipe for writing.

type Reader

type Reader struct {
	ReaderWriter
}

Reader satisfies the fs.FileOperations interface for read-only pipes. Reader should be used with !fs.FileFlags.Write to reject writes.

func (*Reader) Readiness

func (r *Reader) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*Reader) Release

func (r *Reader) Release()

Release implements fs.FileOperations.Release.

type ReaderWriter

type ReaderWriter struct {
	fsutil.PipeSeek      `state:"nosave"`
	fsutil.NotDirReaddir `state:"nosave"`
	fsutil.NoFsync       `state:"nosave"`
	fsutil.NoopFlush     `state:"nosave"`
	fsutil.NoMMap        `state:"nosave"`
	*Pipe
}

ReaderWriter satisfies the FileOperations interface and services both read and write requests. This should only be used directly for named pipes. pipe(2) and pipe2(2) only support unidirectional pipes and should use either pipe.Reader or pipe.Writer.

func (*ReaderWriter) Ioctl

func (rw *ReaderWriter) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error)

Ioctl implements fs.FileOperations.Ioctl.

func (*ReaderWriter) Read

func (rw *ReaderWriter) Read(ctx context.Context, _ *fs.File, dst usermem.IOSequence, _ int64) (int64, error)

Read implements fs.FileOperations.Read.

func (*ReaderWriter) Readiness

func (rw *ReaderWriter) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*ReaderWriter) Release

func (rw *ReaderWriter) Release()

Release implements fs.FileOperations.Release.

func (*ReaderWriter) Write

func (rw *ReaderWriter) Write(ctx context.Context, _ *fs.File, src usermem.IOSequence, _ int64) (int64, error)

Write implements fs.FileOperations.Write.

type Writer

type Writer struct {
	ReaderWriter
}

Writer satisfies the fs.FileOperations interface for write-only pipes. Writer should be used with !fs.FileFlags.Read to reject reads.

func (*Writer) Readiness

func (w *Writer) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*Writer) Release

func (w *Writer) Release()

Release implements fs.FileOperations.Release.

Jump to

Keyboard shortcuts

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