pipes

package
v0.0.0-...-590195b Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pipe

type Pipe interface {
	io.ReadWriteCloser

	// Name of the pipe that was created
	Name() StreamNames
}

Pipe is the interface to interact with the pipes that are created

func NewDuplexPipe

func NewDuplexPipe() (Pipe, error)

NewDuplexPipe returns an io.ReaadWriteCloser that maintains an in and an out pipe to write and read from for inter-process comunication

func NewFifoPipe

func NewFifoPipe(name string, flag int) (Pipe, error)

NewFifoPipe returns an io.ReaadWriteCloser that maintains an in and an out pipe to write and read from for inter-process comunication

Example
// Create a new pipe
pipe, err := NewFifoPipe("test.pipe", os.O_RDWR)
if err != nil {
	panic(err)
}

// Process 1 - Prints to the pipe
go func() {
	fmt.Fprintln(pipe, "Hello pipe!")
}()

// Process 2 - Reads from the pipe
reader := bufio.NewReader(pipe)
result, err := reader.ReadString('\n')
if err != nil {
	panic(err)
}
fmt.Println(result)

// Closing the pipe will also delete the pipe of the same name created
if err := pipe.Close(); err != nil {
	panic(err)
}
Output:

Hello pipe!

func NewNamedDuplexPipe

func NewNamedDuplexPipe(inFile, outFile string) (Pipe, error)

NewNamedDuplexPipe returns an io.ReaadWriteCloser that maintains an in and an out pipe to write and read from for inter-process comunication

func TempFifoPipe

func TempFifoPipe() (Pipe, error)

TempFifoPipe returns a pipe pointing at a temp file with O_RDWR O_APPEND privlages

Example
// Create a new pipe
pipe, err := TempFifoPipe()
if err != nil {
	panic(err)
}

// Process 1 - Prints to the pipe
go func() {
	fmt.Fprintln(pipe, "Hello pipe!")
}()

// Process 2 - Reads from the pipe
reader := bufio.NewReader(pipe)
result, err := reader.ReadString('\n')
if err != nil {
	panic(err)
}
fmt.Println(result)

// Closing the pipe will also delete the pipe of the same name created
if err := pipe.Close(); err != nil {
	panic(err)
}
Output:

Hello pipe!

type StreamNames

type StreamNames struct {
	In, Out string
}

StreamNames contains the io named streams as file names

Jump to

Keyboard shortcuts

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