MCPcopy Index your code
hub / github.com/npat-efault/poller

github.com/npat-efault/poller @v2.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.0 ↗ · + Follow
100 symbols 335 edges 14 files 30 documented · 30% 1 cross-repo links updated 9y agov2.0.0 · 2015-11-19★ 1061 open issues

Browse by type

Functions 91 Types & classes 9
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Core symbols most depended-on inside this repo

Shape

Function 55
Method 36
Struct 5
TypeAlias 4

Languages

Go100%

Modules by API surface

poller.go22 symbols
echo_test.go20 symbols
poller_test.go17 symbols
poller_select.go16 symbols
poller_epoll.go9 symbols
error.go8 symbols
select_cgo.go5 symbols
select_linux.go1 symbols
select_bsd.go1 symbols
poller_epoll_test.go1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add poller \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page