msantos / procket

Erlang interface to low level socket operations
http://blog.listincomprehension.com/search/label/procket
BSD 3-Clause "New" or "Revised" License
283 stars 80 forks source link

Add support for asynch notifications on a file-descriptor #2

Closed ghaskins closed 13 years ago

ghaskins commented 13 years ago

This patch uses libev inside the NIF framework to provide a mechanism for monitoring one or more file-descriptors for changes.

It introduces three more verbs to the procket namespace:

{ok, Handle} = procket:watcher_create(Fd, Flags, Cookie) procket:watcher_arm(Handle) procket:watcher_disarm(Handle)

The idea is that watcher_create takes an Fd, and a set of flags (0x1 for READ, 0x2 for WRITE, 0x3 for READ/WRITE), and an arbitrary term (Cookie).

When the FD becomes ready for either a READ or WRITE, it will fire a msg {procket_watcher, Flags, Cookie} back at the caller and disarm itself.

The user may subsequently re-arm the trigger with procket:watcher_arm() and disarm it with procket:watcher_disarm().

Signed-off-by: Gregory Haskins ghaskins@novell.com

msantos commented 13 years ago

This is just incredible, true {active, once} mode! Thanks so much!