poll

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: BSD-3-Clause Imports: 5 Imported by: 2

README

#poll GoDoc poll is an efficient char device access package for Go

Download:

go get github.com/jaracil/poll

##Description:

Poll is an efficient char device access package for Go, based on Nick Patavalis (npat@efault.net) poller package.

It uses EPOLL(7) on Linux and SELECT(2) on the rest of Posix Oses. Allows concurent Read and Write operations from and to multiple file-descriptors without allocating one OS thread for every blocked operation. It behaves similarly to Go's netpoller (which multiplexes network connections) without requiring special support from the Go runtime.

It can be used with tty devices, character devices, pipes, FIFOs, GPIOs, TUNs/TAPs and any Unix file-descriptor that is epoll(7)-able or select(2)-able. In addition it allows the user to set timeouts (deadlines) for read and write operations.

All operations on *poll.File are thread-safe; you can use the same File from multiple go-routines. It is, for example, safe to close a file blocked on a Read or Write call from another go-routine. In this case all blocked read/write operations are awakened.


Documentation

Index

Constants

View Source
const (
	O_RDONLY   int = syscall.O_RDONLY   // open the file read-only.
	O_WRONLY   int = syscall.O_WRONLY   // open the file write-only.
	O_RDWR     int = syscall.O_RDWR     // open the file read-write.
	O_NONBLOCK int = syscall.O_NONBLOCK // open in non block mode.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error int

Error is the type for the errors returned by poller functions and methods. See also the ErrXXX constants.

const (
	ErrClosed  Error = 1 // Use of closed poller file-descriptor
	ErrTimeout Error = 2 // Operation timed-out
)

Errors returned by poller functions and methods. In addition to these, poller functions and methods may return the errors reported by the underlying system calls (open(2), read(2), write(2), etc.), as well as io.EOF and io.ErrUnexpectedEOF.

func (Error) Error

func (e Error) Error() string

Error returns a string describing the error.

func (Error) Temporary

func (e Error) Temporary() bool

Temporary returns true if the error indicates a temporary condition (re-atempting the operation may succeed).

func (Error) Timeout

func (e Error) Timeout() bool

Timeout returns true if the error indicates a timeout condition.

type File

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

File is an *os.File like object who adds polling capabilities

func NewFile

func NewFile(fd uintptr, name string) (*File, error)

NewFile returns a new File with the given file descriptor and name.

func NewFromFile

func NewFromFile(of OsFile) (*File, error)

NewFromFile returns a new *poll.File based on the given *os.File. You don't need to worry about closing the *os.File, *poll.File already does it.

func Open

func Open(name string, flags int) (*File, error)

Open the named path for reading, writing or both, depnding on the flags argument.

func (*File) Close

func (f *File) Close() error

Close closes the File, rendering it unusable for I/O. It returns an error, if any.

func (*File) Fd

func (f *File) Fd() uintptr

Fd returns the integer Unix file descriptor referencing the open file.

func (*File) Lock

func (f *File) Lock() error

Lock locks the file. It must be called before perfoming miscellaneous operations (e.g. ioctls) on the underlying system file descriptor.

func (*File) Name

func (f *File) Name() string

Name returns the name of the file as presented to Open.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and an error, if any.

func (*File) SetDeadline

func (f *File) SetDeadline(t time.Time) error

SetDeadline sets the deadline for Read and write operations on File.

func (*File) SetReadDeadline

func (f *File) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for Read operations on File.

func (*File) SetWriteDeadline

func (f *File) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for Write operations on File.

func (*File) Unlock

func (f *File) Unlock()

Unlock unlocks the file.

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString is like Write, but writes the contents of string s rather than a slice of bytes.

type OsFile

type OsFile interface {
	Close() error
	Fd() uintptr
	Name() string
}

OsFile interface with *os.File methods used in NewFromFile

Jump to

Keyboard shortcuts

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