fifo

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Overview

Package fifo implements first-in-first-out objects logic. It gives access to OS-native FIFO objects via:

CreateNamedPipe on windows
Mkfifo on unix

Index

Examples

Constants

View Source
const (
	// O_NONBLOCK flag makes Fifo open operation nonblocking.
	O_NONBLOCK = common.O_NONBLOCK
)

Variables

This section is empty.

Functions

func Destroy

func Destroy(name string) error

Destroy permanently removes the FIFO.

func DestroyUnixFIFO

func DestroyUnixFIFO(name string) error

DestroyUnixFIFO permanently removes the FIFO.

Types

type Fifo

type Fifo interface {
	io.ReadWriter
	io.Closer
	Destroy() error
}

Fifo represents a First-In-First-Out object

Example
testData := []byte{1, 2, 3, 4, 5, 6, 7, 8}
go func() {
	fifo, err := New("fifo", os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		panic("new")
	}
	defer fifo.Close()
	if written, err := fifo.Write(testData); err != nil || written != len(testData) {
		panic("write")
	}
}()
buff := make([]byte, len(testData))
fifo, err := New("fifo", os.O_CREATE|os.O_RDONLY, 0666)
if err != nil {
	panic("new")
}
defer fifo.Close()
if read, err := fifo.Read(buff); err != nil || read != len(testData) {
	panic("read")
}
// ensure we've received valid data
for i, b := range buff {
	if b != testData[i] {
		panic("wrong data")
	}
}
Output:

func New

func New(name string, flag int, perm os.FileMode) (Fifo, error)

New creates or opens a new FIFO object

name - object name.
flag - flag is a combination of open flags from 'os' package along with O_NONBLOCK flag.
perm - object's permission bits.

type UnixFifo

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

UnixFifo is a first-in-first-out unix ipc mechanism.

func NewUnixFifo

func NewUnixFifo(name string, flag int, perm os.FileMode) (*UnixFifo, error)

NewUnixFifo creates a new unix FIFO.

name - object name.
flag - flag is a combination of open flags from 'os' package.
perm = object permissions.

func (*UnixFifo) Close

func (f *UnixFifo) Close() error

Close closes the object.

func (*UnixFifo) Destroy

func (f *UnixFifo) Destroy() error

Destroy permanently removes the FIFO, closing it first.

func (*UnixFifo) Read

func (f *UnixFifo) Read(b []byte) (n int, err error)

Read reads from the given FIFO. it must be opened for reading.

func (*UnixFifo) Write

func (f *UnixFifo) Write(b []byte) (n int, err error)

Write writes to the given FIFO. it must be opened for writing.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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