<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Usage</title><link>https://sourceforge.net/p/libkqueue/wiki/Usage/</link><description>Recent changes to Usage</description><atom:link href="https://sourceforge.net/p/libkqueue/wiki/Usage/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 30 Apr 2013 01:44:07 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/libkqueue/wiki/Usage/feed" rel="self" type="application/rss+xml"/><item><title>Usage modified by Mark Heily</title><link>https://sourceforge.net/p/libkqueue/wiki/Usage/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="Usage"&gt;
    Usage&lt;/h1&gt;

&lt;p&gt;
    Here are some issues to be aware of when using this library under any platform:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;
        The EVFILT_PROC filter is not implemented.&lt;/li&gt;
    &lt;li&gt;
        The EVFILT_AIO filter is not implemented.&lt;/li&gt;
    &lt;li&gt;
        When a kqueue descriptor is closed, it's resources are not immediately reclaimed. Instead, they will be freed the next time that the kqueue() function is called.&lt;/li&gt;
    &lt;li&gt;
        A signal handler is implicitly installed when a EVFILT_SIGNAL kevent is created. For compatibility with kernel-based &lt;strong&gt;kqueue(2)&lt;/strong&gt;, programs must ignore signals that will generate kevents. After an EVFILT_SIGNAL kevent is created, a program must not modify the disposition of the associated signal. The following example shows the proper way to handle SIGUSR1 with a kevent:&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="wiki"&gt;
int main() {
  int kqfd;
  struct kevent kev;

  kqfd = kqueue();
  signal(SIGUSR1, SIG_IGN);
  EV_SET(&amp;amp;kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
  kevent(kqfd, &amp;amp;kev, 1, NULL, 0, NULL);
}
&lt;/pre&gt;

&lt;p&gt;
    There are additional considerations listed below that are platform-specific.&lt;/p&gt;

&lt;h2 id="Linux"&gt;
    Linux&lt;/h2&gt;

&lt;p&gt;
    There are several compatibility issues to be aware of when using this library under Linux:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;
        The NOTE_LOWAT flag is not supported. According to &lt;strong&gt;socket(7)&lt;/strong&gt;,
        &lt;pre class="wiki"&gt;
        &amp;quot;The select(2) and poll(2) system  calls  currently  do not respect the 
SO_RCVLOWAT setting on Linux, and mark a socket readable when even  a  
single  byte  of data is available.  A subsequent read from the socket 
will block until SO_RCVLOWAT bytes are available.&amp;quot;
&lt;/pre&gt;
    &lt;/li&gt;
    &lt;li&gt;
        The NOTE_REVOKE flag is not supported because Linux does not have a &lt;strong&gt;revoke(2)&lt;/strong&gt; system call.&lt;/li&gt;
    &lt;li&gt;
        When an EVFILT_SIGNAL event is generated, the &lt;i&gt;data&lt;/i&gt; field is set to 1 regardless of how many times the signal was received by the process.&lt;/li&gt;
    &lt;li&gt;
        When an EVFILT_READ event occurs on a listening socket, the &lt;i&gt;data&lt;/i&gt; field is set to 1 regardless of how many pending connections are available.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="Solaris"&gt;
    Solaris&lt;/h2&gt;

&lt;p&gt;
    Here are the issues to be aware of when using this library under Solaris:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;
        Solaris 10 or newer is required. It should work with &lt;a class="missing wiki" href="/trac/libkqueue/wiki/OpenSolaris" rel="nofollow"&gt;OpenSolaris?&lt;/a&gt; and other Solaris-based distributions, but has not been tested.&lt;/li&gt;
    &lt;li&gt;
        When an EVFILT_READ event is generated, the &lt;i&gt;data&lt;/i&gt; field is set to 1 regardless of how many bytes are available to read.&lt;/li&gt;
    &lt;li&gt;
        When an EVFILT_TIMER event is generated, the &lt;i&gt;data&lt;/i&gt; field is set to 1 regardless of how many times the timer has been triggered.&lt;/li&gt;
    &lt;li&gt;
        The EVFILT_VNODE filter is not implemented. This will eventually be implemented using the PORT_SOURCE_FILE mechanism described &lt;a class="ext-link" href="http://blogs.sun.com/praks/entry/file_events_notification"&gt;&lt;span class="icon"&gt; &lt;/span&gt;here&lt;/a&gt;.&lt;/li&gt;
    &lt;li&gt;
        The EVFILT_TIMER filter is implemented using high-resolution timers. In order to use high-resolution timers, the calling process must hold the PRIV_PROC_CLOCK_HIGHRES privilege. This privilege is not granted to ordinary users by default. It can be granted to individual users by running the following command as root:
        &lt;pre class="wiki"&gt;
        # usermod -K defaultpriv=basic,proc_clock_highres $user
&lt;/pre&gt;
    &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="BSD-basedsystems"&gt;
    BSD-based systems&lt;/h2&gt;

&lt;p&gt;
    There are some differences in the behavior of the &lt;i&gt;kevent(2)&lt;/i&gt; system call across the various BSD-based operating systems. Here are some of the differences to be aware of:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;
        FreeBSD 8 does not set the &lt;i&gt;EV_ADD&lt;/i&gt; flag for kevents on the eventlist, but OpenBSD and Darwin do. This means you should never use the equality operator (==) to test the flags; use the logical AND operator instead.&lt;/li&gt;
    &lt;li&gt;
        The EVFILT_USER filter behaves differently from other filters with respect to the &lt;i&gt;EV_ONESHOT&lt;/i&gt; flag. All other filters will preserve the flag when the event is triggered and placed on the eventlist. The EVFILT_USER filter does not preserve this flag.&lt;/li&gt;
    &lt;li&gt;
        OpenBSD has the &lt;i&gt;NOTE_TRUNCATE&lt;/i&gt; fflag, while FreeBSD and Darwin do not.&lt;/li&gt;
    &lt;li&gt;
        EVFILT_FS is undocumented and only available on FreeBSD and Darwin. Here is the &lt;a class="ext-link" href="http://adam.kungfoohampster.com/lists/cvs-all/msg71399.shtml"&gt;&lt;span class="icon"&gt; &lt;/span&gt;CVS commit log&lt;/a&gt; which could be helpful to document this filter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id="Integration"&gt;
    Integration&lt;/h1&gt;

&lt;h2 id="OrdinaryMakefile"&gt;
    Ordinary Makefile&lt;/h2&gt;

&lt;p&gt;
    Here are the steps to use libkqueue in your program if you use an ordinary Makefile:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;
        Add &lt;tt&gt;pkg-config libkqueue --cflags&lt;/tt&gt; to the CFLAGS variable.&lt;/li&gt;
    &lt;li&gt;
        Add &lt;tt&gt;pkg-config libkqueue --libs&lt;/tt&gt; to the LDADD variable.&lt;/li&gt;
    &lt;li&gt;
        Add &amp;quot;#include &amp;lt;sys/event.h&amp;gt;&amp;quot; to the source code.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id="AutoconfAutomakeLibtool"&gt;
    Autoconf/Automake/Libtool&lt;/h2&gt;

&lt;p&gt;
    If your program uses the GNU Autoconf/Automake/Libtool build system, the following steps will allow you to use libkqueue:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt;
        Add the following to configure.ac:
        &lt;pre class="wiki"&gt;
        #
# Prefer native kqueue(2); otherwise use libkqueue if present.
#
AC_CHECK_HEADER(sys/event.h, [],
  [PKG_CHECK_MODULES(KQUEUE, libkqueue)]
)
&lt;/pre&gt;
    &lt;/li&gt;
    &lt;li&gt;
        Add the following to &lt;i&gt;Makefile.am&lt;/i&gt; (assuming your program is named &amp;quot;foo&amp;quot;):
        &lt;pre class="wiki"&gt;
        foo_CFLAGS+=$(KQUEUE_CFLAGS)
foo_LDADD+=$(KQUEUE_LIBS)
&lt;/pre&gt;
    &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
    Instead of using the &lt;i&gt;$(KQUEUE_LIBS)&lt;/i&gt; variable, you could just add libkqueue.la to your programs LDADD variable.&lt;/p&gt;

&lt;h2 id="Threads"&gt;
    Threads&lt;/h2&gt;

&lt;p&gt;
    libkqueue uses one or more helper threads, so all programs that link with libkqueue must also link against the pthreads library. Calls to &lt;strong&gt;kqueue()&lt;/strong&gt; and &lt;strong&gt;kevent()&lt;/strong&gt; are safe to be used from multiple threads.&lt;/p&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mark Heily</dc:creator><pubDate>Tue, 30 Apr 2013 01:44:07 -0000</pubDate><guid>https://sourceforge.net2d47e0b5a1a5bdc4ed56ede295a4550f201e1428</guid></item></channel></rss>