NAME

IO::KQueue - perl interface to the BSD kqueue system call

SYNOPSIS

my $kq = IO::KQueue->new();
$kq->EV_SET($fd, EVFILT_READ, EV_ADD, 0, 5);

my %results = $kq->kevent($timeout);

DESCRIPTION

This module provides a fairly low level interface to the BSD kqueue() system call, allowing you to monitor for changes on sockets, files, processes and signals.

Usage is very similar to the kqueue system calls, so you will need to have read and understood the kqueue man page. This document may seem fairly light on details but that is merely because the details are in the man page, and so I don't wish to replicate them here.

API

IO::KQueue->new()

Construct a new KQueue object (maps to the kqueue() system call).

$kq->EV_SET($ident, $filt, $flags, $fflags, $data, $udata)

e.g.:

$kq->EV_SET(fileno($server), EVFILT_READ, EV_ADD, 0, 5);

Equivalent to the EV_SET macro followed immediately by a call to kevent() to set the event up.

Note that to watch for both read and write events you need to call this method twice - once with EVFILT_READ and once with EVFILT_WRITE - unlike epoll() and poll() these "filters" are not a bitmask.

Returns nothing. Throws an exception on failure.

The $fflags, $data and $udata params are optional.

$kq->kevent($timeout)

Poll for events on the kqueue. Timeout is in milliseconds. If timeout is zero or ommitted then we poll forever until there are events to read.

Returns a list of (ident, filt) pairs which you can either assign directly to a hash, or iterate through. See the included chat.pl program for an example usage.

NOTE: The API here may be extended to return additional flags. Email the author for ideas about this.

CONSTANTS

For a list of exported constants see the source of Makefile.PL, or the kqueue man page.

LICENSE

This is free software. You may use it and distribute it under the same terms as Perl itself - i.e. either the Perl Artistic License, or the GPL version 2.0.

AUTHOR

Matt Sergeant, <matt@sergeant.org>

Copyright 2005 MessageLabs Ltd.

SEE ALSO

IO::Poll