pipe

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package pipe provides a pipe implementation.

Index

Constants

View Source
const (
	// MinimumPipeSize is a hard limit of the minimum size of a pipe.
	// It corresponds to fs/pipe.c:pipe_min_size.
	MinimumPipeSize = hostarch.PageSize

	// MaximumPipeSize is a hard limit on the maximum size of a pipe.
	// It corresponds to fs/pipe.c:pipe_max_size.
	MaximumPipeSize = 1048576

	// DefaultPipeSize is the system-wide default size of a pipe in bytes.
	// It corresponds to pipe_fs_i.h:PIPE_DEF_BUFFERS.
	DefaultPipeSize = 16 * hostarch.PageSize
)

Variables

This section is empty.

Functions

func Splice

func Splice(ctx context.Context, dst, src *VFSPipeFD, count int64) (int64, error)

Splice reads up to count bytes from src and writes them to dst. It returns the number of bytes moved.

Preconditions: count > 0.

func Tee

func Tee(ctx context.Context, dst, src *VFSPipeFD, count int64) (int64, error)

Tee reads up to count bytes from src and writes them to dst, without removing the read bytes from src. It returns the number of bytes copied.

Preconditions: count > 0.

Types

type Pipe

type Pipe struct {
	// 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.

+stateify savable

func NewPipe

func NewPipe(isNamed bool, sizeBytes int64) *Pipe

NewPipe initializes and returns a pipe.

N.B. The size will be bounded.

func (*Pipe) EventRegister

func (p *Pipe) EventRegister(e *waiter.Entry) error

EventRegister implements waiter.Waitable.EventRegister.

func (*Pipe) EventUnregister

func (p *Pipe) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

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

func (p *Pipe) Ioctl(ctx context.Context, io usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)

Ioctl implements ioctls on the Pipe.

func (*Pipe) Read

func (p *Pipe) Read(ctx context.Context, dst usermem.IOSequence) (int64, error)

Read reads from the Pipe into dst.

func (*Pipe) ReadFrom

func (p *Pipe) ReadFrom(ctx context.Context, r io.Reader, count int64) (int64, error)

ReadFrom reads from r to the Pipe.

func (*Pipe) Readiness

func (p *Pipe) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness returns the ready events in the underlying pipe.

func (*Pipe) Release

func (p *Pipe) Release(context.Context)

Release cleans up the pipe's state.

func (*Pipe) SetFifoSize

func (p *Pipe) SetFifoSize(size int64) (int64, error)

SetFifoSize implements fs.FifoSizer.SetFifoSize.

func (*Pipe) Write

func (p *Pipe) Write(ctx context.Context, src usermem.IOSequence) (int64, error)

Write writes to the Pipe from src.

func (*Pipe) WriteTo

func (p *Pipe) WriteTo(ctx context.Context, w io.Writer, count int64, dup bool) (int64, error)

WriteTo writes to w from the Pipe.

type VFSPipe

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

VFSPipe represents the actual pipe, analogous to an inode. VFSPipes should not be copied.

+stateify savable

func NewVFSPipe

func NewVFSPipe(isNamed bool, sizeBytes int64) *VFSPipe

NewVFSPipe returns an initialized VFSPipe.

func (*VFSPipe) Allocate

Allocate implements vfs.FileDescriptionImpl.Allocate.

func (*VFSPipe) Open

func (vp *VFSPipe) Open(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, statusFlags uint32, locks *vfs.FileLocks) (*vfs.FileDescription, error)

Open opens the pipe represented by vp.

func (*VFSPipe) ReaderWriterPair

func (vp *VFSPipe) ReaderWriterPair(ctx context.Context, mnt *vfs.Mount, vfsd *vfs.Dentry, statusFlags uint32) (*vfs.FileDescription, *vfs.FileDescription, error)

ReaderWriterPair returns read-only and write-only FDs for vp.

Preconditions: statusFlags should not contain an open access mode.

type VFSPipeFD

type VFSPipeFD struct {
	vfs.FileDescriptionDefaultImpl
	vfs.DentryMetadataFileDescriptionImpl
	vfs.LockFD
	// contains filtered or unexported fields
}

VFSPipeFD implements vfs.FileDescriptionImpl for pipes. It also implements non-atomic usermem.IO methods, allowing it to be passed as usermem.IO to other FileDescriptions for splice(2) and tee(2).

+stateify savable

func (*VFSPipeFD) Allocate

func (fd *VFSPipeFD) Allocate(ctx context.Context, mode, offset, length uint64) error

Allocate implements vfs.FileDescriptionImpl.Allocate.

func (*VFSPipeFD) CompareAndSwapUint32

func (fd *VFSPipeFD) CompareAndSwapUint32(ctx context.Context, addr hostarch.Addr, old, new uint32, opts usermem.IOOpts) (uint32, error)

CompareAndSwapUint32 implements usermem.IO.CompareAndSwapUint32.

func (*VFSPipeFD) CopyIn

func (fd *VFSPipeFD) CopyIn(ctx context.Context, addr hostarch.Addr, dst []byte, opts usermem.IOOpts) (int, error)

CopyIn implements usermem.IO.CopyIn. Note that it is the caller's responsibility to call fd.pipe.Notify(waiter.WritableEvents) after the read is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) CopyInTo

func (fd *VFSPipeFD) CopyInTo(ctx context.Context, ars hostarch.AddrRangeSeq, dst safemem.Writer, opts usermem.IOOpts) (int64, error)

CopyInTo implements usermem.IO.CopyInTo. Note that it is the caller's responsibility to call fd.pipe.consumeLocked() and fd.pipe.queue.Notify(waiter.WritableEvents) after the read is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) CopyOut

func (fd *VFSPipeFD) CopyOut(ctx context.Context, addr hostarch.Addr, src []byte, opts usermem.IOOpts) (int, error)

CopyOut implements usermem.IO.CopyOut. Note that it is the caller's responsibility to call fd.pipe.queue.Notify(waiter.ReadableEvents) after the write is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) CopyOutFrom

func (fd *VFSPipeFD) CopyOutFrom(ctx context.Context, ars hostarch.AddrRangeSeq, src safemem.Reader, opts usermem.IOOpts) (int64, error)

CopyOutFrom implements usermem.IO.CopyOutFrom. Note that it is the caller's responsibility to call fd.pipe.queue.Notify(waiter.ReadableEvents) after the write is completed.

Preconditions: fd.pipe.mu must be locked.

func (*VFSPipeFD) Epollable

func (fd *VFSPipeFD) Epollable() bool

Epollable implements FileDescriptionImpl.Epollable.

func (*VFSPipeFD) EventRegister

func (fd *VFSPipeFD) EventRegister(e *waiter.Entry) error

EventRegister implements waiter.Waitable.EventRegister.

func (*VFSPipeFD) EventUnregister

func (fd *VFSPipeFD) EventUnregister(e *waiter.Entry)

EventUnregister implements waiter.Waitable.EventUnregister.

func (*VFSPipeFD) Ioctl

func (fd *VFSPipeFD) Ioctl(ctx context.Context, uio usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)

Ioctl implements vfs.FileDescriptionImpl.Ioctl.

func (*VFSPipeFD) LoadUint32

func (fd *VFSPipeFD) LoadUint32(ctx context.Context, addr hostarch.Addr, opts usermem.IOOpts) (uint32, error)

LoadUint32 implements usermem.IO.LoadUint32.

func (*VFSPipeFD) PipeSize

func (fd *VFSPipeFD) PipeSize() int64

PipeSize implements fcntl(F_GETPIPE_SZ).

func (*VFSPipeFD) Read

Read implements vfs.FileDescriptionImpl.Read.

func (*VFSPipeFD) Readiness

func (fd *VFSPipeFD) Readiness(mask waiter.EventMask) waiter.EventMask

Readiness implements waiter.Waitable.Readiness.

func (*VFSPipeFD) Release

func (fd *VFSPipeFD) Release(context.Context)

Release implements vfs.FileDescriptionImpl.Release.

func (*VFSPipeFD) SetPipeSize

func (fd *VFSPipeFD) SetPipeSize(size int64) (int64, error)

SetPipeSize implements fcntl(F_SETPIPE_SZ).

func (*VFSPipeFD) SpliceFromNonPipe

func (fd *VFSPipeFD) SpliceFromNonPipe(ctx context.Context, in *vfs.FileDescription, off, count int64) (int64, error)

SpliceFromNonPipe performs a splice operation from a non-pipe file to fd.

func (*VFSPipeFD) SpliceToNonPipe

func (fd *VFSPipeFD) SpliceToNonPipe(ctx context.Context, out *vfs.FileDescription, off, count int64) (int64, error)

SpliceToNonPipe performs a splice operation from fd to a non-pipe file.

func (*VFSPipeFD) SwapUint32

func (fd *VFSPipeFD) SwapUint32(ctx context.Context, addr hostarch.Addr, new uint32, opts usermem.IOOpts) (uint32, error)

SwapUint32 implements usermem.IO.SwapUint32.

func (*VFSPipeFD) Write

Write implements vfs.FileDescriptionImpl.Write.

func (*VFSPipeFD) ZeroOut

func (fd *VFSPipeFD) ZeroOut(ctx context.Context, addr hostarch.Addr, toZero int64, opts usermem.IOOpts) (int64, error)

ZeroOut implements usermem.IO.ZeroOut.

Preconditions: fd.pipe.mu must be locked.

Jump to

Keyboard shortcuts

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