<?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> <chapter xml:id="libevent.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> &reftitle.examples; <para> <example> <title>polling <constant>STDIN</constant> using basic API</title> <programlisting role="php"> <![CDATA[ <?php function print_line($fd, $events, $arg) { static $max_requests = 0; $max_requests++; if ($max_requests == 10) { // exit loop after 10 writes event_base_loopexit($arg[1]); } // print the line echo fgets($fd); } // create base and event $base = event_base_new(); $event = event_new(); $fd = STDIN; // set event flags event_set($event, $fd, EV_READ | EV_PERSIST, "print_line", array($event, $base)); // set event base event_base_set($event, $base); // enable event event_add($event); // start event loop event_base_loop($base); ?> ]]> </programlisting> </example> </para> <para> <example> <title>polling <constant>STDIN</constant> using buffered event API</title> <programlisting role="php"> <![CDATA[ <?php function print_line($buf, $arg) { static $max_requests; $max_requests++; if ($max_requests == 10) { event_base_loopexit($arg); } // print the line echo event_buffer_read($buf, 4096); } function error_func($buf, $what, $arg) { // handle errors } $base = event_base_new(); $eb = event_buffer_new(STDIN, "print_line", NULL, "error_func", $base); event_buffer_base_set($eb, $base); event_buffer_enable($eb, EV_READ); event_base_loop($base); ?> ]]> </programlisting> </example> </para> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"~/.phpdoc/manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->