rn

rn provides a more or less convenient wrapper around two very efficient notification mechanisms, sigio and epoll. See www.kegel.com/c10k.html for a description of these two mechanisms. Basically, they are standard Linux replacements for poll that are much more efficient. The right one to use is almost always epoll; sigio is only a fallback, as it's less efficient.

The odd thing about rn is that you have to tell it the maximum number of file descriptors you expect to have to use, and (if you want to work with sigio) you have to tell it which realtime signal to use to deliver its notifications.

The epoll library must be installed before you can build rn.

Using rn

The api is fairly simple; see rn_test.c for an example.

Here are the steps to add rn support to a program currently using poll():

Unit test

The rn library comes with a test program which doubles as a demo. The test program is unfortunately not standalone -- it relies on the 'chargen' tcp server, which you may have to enable by editing /etc/inetd.conf, then restarting inetd.

Here's what a successful run looks like:

# ./rn_test
fn: revents 4
rn_POLLOUT
fn: revents 5
fn: read returns 1024, errno 11
... (repeats 62 times)
fn: read returns 1024, errno 11
fn: read returns 977, errno 11
Read 66513 bytes
PASS
If you're debugging a program that uses rn, you may wish to rebuild rn with dprints enabled. To do this, uncomment the lines
/* #define dprint_ENABLED */
/* #define dprint_TRACE_ENABLED */
in rn_dprint.h, and rebuild and reinstall rn. With dprint enabled, a successful run looks like this:
# ./rn_test
-469985671:47:rn_sys_epoll.c:rn_sys_epoll_init  init()
-469985652:150:rn_sys_epoll.c:rn_sys_epoll_add  add(4, 0x10000954, (nil)) this->m_fds_used 1
-469985651:198:rn_sys_epoll.c:rn_sys_epoll_waitAndDispatchEvents        Calling epoll...
-469985651:200:rn_sys_epoll.c:rn_sys_epoll_waitAndDispatchEvents        epoll returns 1 fds. errno: 11-469985651:213:rn_sys_epoll.c:rn_sys_epoll_waitAndDispatchEvents        fd 4, revents 4
fn: revents 4
rn_POLLOUT
-469985651:198:rn_sys_epoll.c:rn_sys_epoll_waitAndDispatchEvents        Calling epoll...
-469985638:200:rn_sys_epoll.c:rn_sys_epoll_waitAndDispatchEvents        epoll returns 1 fds. errno: 11-469985638:213:rn_sys_epoll.c:rn_sys_epoll_waitAndDispatchEvents        fd 4, revents 5
fn: revents 5
fn: read returns 1024, errno 11
... (62 lines like the one above)
fn: read returns 1024, errno 11
fn: read returns 118, errno 11
Read 65654 bytes
-469985628:160:rn_sys_epoll.c:rn_sys_epoll_del  del(fd 4)
PASS

Last change: 10 Nov 2003
Portions Copyright 2002 Dan Kegel
Portions Copyright 2003 Ixia Communications
Licensed under the LGPL
[Return to kegel.com/rn]