proxy

package
v0.0.0-...-a905e96 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transfer

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.

Conceptually:

Transfer(upstream, downstream)

is equivalent to

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

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

Types

type Pipe

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

A Pipe is a buffered, unidirectional data channel.

func NewPipe

func NewPipe() (*Pipe, error)

NewPipe creates a new pipe.

func (*Pipe) BufferSize

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

BufferSize returns the buffer size of the pipe.

func (*Pipe) Close

func (p *Pipe) Close() error

Close closes both sides of the pipe.

func (*Pipe) CloseRead

func (p *Pipe) CloseRead() error

CloseRead closes the read side of the pipe.

func (*Pipe) CloseWrite

func (p *Pipe) CloseWrite() error

CloseWrite closes the write side of the pipe.

func (*Pipe) Read

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

Read reads data from the pipe.

func (*Pipe) ReadFrom

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

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

SetBufferSize sets the pipe's buffer size to n.

func (*Pipe) Tee

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

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

Write writes data to the pipe.

func (*Pipe) WriteTo

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.

Jump to

Keyboard shortcuts

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