zerocopy: Index | Files

package zerocopy

import ""


Package Files

zerocopy.go zerocopy_linux.go

func Transfer Uses

func Transfer(dst io.Writer, src io.Reader) (int64, error)

Transfer is like io.Copy, but moves data through a pipe rather than through a userspace buffer. Given a pipe p, Transfer operates equivalently to p.ReadFrom(src) and p.WriteTo(dst), but in lock-step, and with no need to create additional goroutines.


Transfer(upstream, downstream)

is equivalent to

p, _ := NewPipe()
go p.ReadFrom(downstream)

but in more compact form, and slightly more resource-efficient.

type Pipe Uses

type Pipe struct {
    // contains filtered or unexported fields

A Pipe is a buffered, unidirectional data channel.

func NewPipe Uses

func NewPipe() (*Pipe, error)

NewPipe creates a new pipe.

func (*Pipe) BufferSize Uses

func (p *Pipe) BufferSize() (int, error)

BufferSize returns the buffer size of the pipe.

func (*Pipe) Close Uses

func (p *Pipe) Close() error

Close closes both sides of the pipe.

func (*Pipe) CloseRead Uses

func (p *Pipe) CloseRead() error

CloseRead closes the read side of the pipe.

func (*Pipe) CloseWrite Uses

func (p *Pipe) CloseWrite() error

CloseWrite closes the write side of the pipe.

func (*Pipe) Read Uses

func (p *Pipe) Read(b []byte) (n int, err error)

Read reads data from the pipe.

func (*Pipe) ReadFrom Uses

func (p *Pipe) ReadFrom(src io.Reader) (int64, error)

ReadFrom transfers data from src to the pipe.

If src implements syscall.Conn, ReadFrom tries to use splice(2) for the data transfer from the source file descriptor to the pipe. If that is not possible, ReadFrom falls back to a generic copy.

func (*Pipe) SetBufferSize Uses

func (p *Pipe) SetBufferSize(n int) error

SetBufferSize sets the pipe's buffer size to n.

func (*Pipe) Tee Uses

func (p *Pipe) Tee(w io.Writer)

Tee arranges for data in the read side of the pipe to be mirrored to the specified writer. There is no internal buffering: writes must complete before the associated read completes.

If the argument is of concrete type *Pipe, the tee(2) system call is used when mirroring data from the read side of the pipe.

Tee must not be called concurrently with I/O methods, and must be called only once, and before any calls to Read or WriteTo.

func (*Pipe) Write Uses

func (p *Pipe) Write(b []byte) (n int, err error)

Write writes data to the pipe.

func (*Pipe) WriteTo Uses

func (p *Pipe) WriteTo(dst io.Writer) (int64, error)

WriteTo transfers data from the pipe to dst.

If dst implements syscall.Conn, WriteTo tries to use splice(2) for the data transfer from the pipe to the destination file descriptor. If that is not possible, WriteTo falls back to a generic copy.

Package zerocopy imports 4 packages (graph) and is imported by 1 packages. Updated 2019-04-11. Refresh now. Tools for package owners.