An epoll(7)-based file-descriptor multiplexer.

Related tags

File Handling poller
Overview

poller GoDoc

Package poller is a file-descriptor multiplexer.

Download:

go get github.com/npat-efault/poller

Package poller is a file-descriptor multiplexer. It allows concurent Read and Write operations from and to multiple file-descriptors without allocating one OS thread for every blocked operation. It operates 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, and any file-descriptor that is poll-able (can be used with select(2), epoll(7), etc.) In addition, package poller allows the user to set timeouts (deadlines) for read and write operations, and also allows for safe cancelation of blocked read and write operations; a Close from another go-routine safely cancels ongoing (blocked) read and write operations.

Typical usage

fd, err: = poller.Open("/dev/ttyXX", poller.O_RW)
if err != nil {
    log.Fatal("Failed to open device:", err)
}

...

err = fd.SetReadDeadline(time.Now().Add(5 * time.Second))
if err != nil {
    log.Fatal("Failed to set R deadline:", err)
}

b := make([]byte, 10)
n, err := fd.Read(b)
if err != nil {
    log.Fatal("Read failed:", err)
}

...

n, err = fd.Write([]byte("Test"))
if err != nil {
    log.Fatal("Write failed:", err)
}

All operations on poller FDs are thread-safe; you can use the same FD from multiple go-routines. It is, for example, safe to close a file descriptor blocked on a Read or Write call from another go-routine.

Supported systems

Linux systems are supported using an implementations based on epoll(7).

For other POSIX systems (that is, most Unix-like systems), a more portable fallback implementation based on select(2) is provided. It has the same semantics as the Linux epoll(7)-based implementation, but is expected to be of lower performance. The select(2)-based implementation uses CGo for some ancillary select-related operations.

Ideally, system-specific io-multiplexing or async-io facilities (e.g. kqueue(2), or /dev/poll(7)) should be used to provide higher performance implementations for other systems. Patches for this will be greatly appreciated.

If you wish, you can build package poller on Linux to use the select(2)-based implementation instead of the epoll(7) one. To do this define the build-tag "noepoll". Normally, there is no reason to do this.

You might also like...
Goful is a CUI file manager written in Go.
Goful is a CUI file manager written in Go.

Goful Goful is a CUI file manager written in Go. Works on cross-platform such as gnome-terminal and cmd.exe. Displays multiple windows and workspaces.

Read a tar file contents using go1.16 io/fs abstraction
Read a tar file contents using go1.16 io/fs abstraction

go-tarfs Read a tar file contents using go1.16 io/fs abstraction Usage โš ๏ธ go-tarfs needs go=1.16 Install: go get github.com/nlepage/go-tarfs Use: pac

Open Source Continuous File Synchronization
Open Source Continuous File Synchronization

Goals Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers. We strive to fulfill the goals belo

Cross-platform file system notifications for Go.

File system notifications for Go fsnotify utilizes golang.org/x/sys rather than syscall from the standard library. Ensure you have the latest version

The best HTTP Static File Server, write with golang+vue
The best HTTP Static File Server, write with golang+vue

gohttpserver Goal: Make the best HTTP File Server. Features: Human-friendly UI, file uploading support, direct QR-code generation for Apple & Android

๐Ÿ“‚ Web File Browser
๐Ÿ“‚ Web File Browser

filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files.

Plik is a scalable & friendly temporary file upload system ( wetransfer like ) in golang.

Want to chat with us ? Telegram channel : https://t.me/plik_root_gg Plik Plik is a scalable & friendly temporary file upload system ( wetransfer like

File system for GitHub
File system for GitHub

HUBFS ยท File System for GitHub HUBFS is a read-only file system for GitHub and Git. Git repositories and their contents are represented as regular dir

Go library for the TOML file format

Go-toml provides the following features for using data parsed from TOML documents

Comments
  • Close method is unsafe.

    Close method is unsafe.

    If Close method is called more than one time then the second call could close an invalid or in use file descriptor.

    I think this method must check fd.closed flag:

    func (fd *FD) Close() error {
        // Take both locks, to exclude read and write operations from
        // accessing a closed sysfd.
        if err := fd.Lock(); err != nil {
            debugf("FD %03d: CL: Closed", fd.id)
            return err
        }
        defer fd.Unlock()
    +   if fd.closed {
    +       return ErrClosed
    +   }
        fd.closed = true
            ...
    

    Thanks.

    opened by jaracil 2
  • syscall.EpollCreate and signal.Notify

    syscall.EpollCreate and signal.Notify

    General Question

    Have you tried using this package along with catching an os.Interrupt signal? poller.EpollWait() will not return when signal.Notify(<>, os.Interrupt) is used. In C, one can create a pair of pipes and add them to epoll_wait(), but go syscall.EpollCtrl() errors with a bad file descriptor for os.Files from os.Pipe(). So this method cannot be used to break out of EpollWait().

    opened by aletheia7 1
  • Add implementation based on kqueue

    Add implementation based on kqueue

    For BSD-derived systems that support it, a kqueue(2) based implementation would provide performance similar to the Linux epoll(7)-based one, without the limitations of select(2). It will also be very similar (trivial modifications) to the epoll(7)-based impl. Add one.

    enhancement 
    opened by npat-efault 1
Releases(v2.0.0)
  • v2.0.0(Nov 19, 2015)

    API changes:

    • The Error type is no longer exported. The same error values (global vars) as before are still exported, but now they are of type "error".

    This is the only API change. Release 2.0.0 will work as a drop-in replacement of release 1.0.0 in almost all cases.

    Added functionality:

    • Better locking for misc operations (e.g ioctls). See this
    • Support for more systems (not only Linux) by a fallback implementation based on select(2). Most Unix-like system should now be supported.
    • Other minor improvements, see commit-log for details

    Tested on:

    Release 2.0.0 has been tested on Linux and FreeBSD. It is expected to work on all POSIX-compatible (i.e. most Unix-like) systems. Success and failure reports are welcome. Email me or open an issue.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Nov 19, 2015)

Owner
Nick Patavalis
Nick Patavalis
Dragonfly is an intelligent P2P based image and file distribution system.

Dragonfly Note: The master branch may be in an unstable or even broken state during development. Please use releases instead of the master branch in o

dragonflyoss 6k Jan 9, 2023
Fast, dependency-free, small Go package to infer the binary file type based on the magic numbers signature

filetype Small and dependency free Go package to infer file and MIME type checking the magic numbers signature. For SVG file type checking, see go-is-

Tom 1.7k Jan 3, 2023
Abstract File Storage

afs - abstract file storage Please refer to CHANGELOG.md if you encounter breaking changes. Motivation Introduction Usage Matchers Content modifiers S

Viant, Inc 221 Dec 30, 2022
a tool for handling file uploads simple

baraka a tool for handling file uploads for http servers makes it easier to make operations with files from the http request. Contents Install Simple

Enes Furkan Olcay 46 Nov 30, 2022
Bigfile -- a file transfer system that supports http, rpc and ftp protocol https://bigfile.site

Bigfile โ€”โ€”โ€”โ€” a file transfer system that supports http, rpc and ftp protocol ็ฎ€ไฝ“ไธญๆ–‡ โˆ™ English Bigfile is a file transfer system, supports http, ftp and

null 238 Dec 31, 2022
Go file operations library chasing GNU APIs.

flop flop aims to make copying files easier in Go, and is modeled after GNU cp. Most administrators and engineers interact with GNU utilities every da

The Home Depot 33 Nov 10, 2022
Read csv file from go using tags

go-csv-tag Read csv file from Go using tags The project is in maintenance mode. It is kept compatible with changes in the Go ecosystem but no new feat

Louis 101 Nov 16, 2022
File system event notification library on steroids.

notify Filesystem event notification library on steroids. (under active development) Documentation godoc.org/github.com/rjeczalik/notify Installation

Rafal Jeczalik 788 Dec 31, 2022
Pluggable, extensible virtual file system for Go

vfs Package vfs provides a pluggable, extensible, and opinionated set of file system functionality for Go across a number of file system types such as

C2FO 212 Jan 3, 2023
QueryCSV enables you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to a CSV file

QueryCSV enable you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to CSV file

Mohamed Shapan 100 Dec 22, 2021