Advertisement
Guest User

libevent possible bug

a guest
Mar 22nd, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Loop {
  4.  
  5.     protected $eventBase;
  6.  
  7.     public function __construct() {
  8.  
  9.         $this->eventBase = event_base_new();
  10.  
  11.     }
  12.  
  13.     public function add($event) {
  14.  
  15.         event_base_set($event, $this->eventBase);
  16.         event_add($event);
  17.  
  18.     }
  19.  
  20.     public function loop() {
  21.  
  22.         event_base_loop($this->eventBase);
  23.  
  24.     }
  25.  
  26. }
  27.  
  28. class ReadableStream  {
  29.  
  30.     protected $handle;
  31.  
  32.     function __construct($handle, Loop $loop) {
  33.  
  34.         $this->handle = $handle;
  35.         $lEvent = event_new();
  36.  
  37.         event_set($lEvent, $this->handle, EV_READ | EV_PERSIST, array($this,'handleEvent'));
  38.  
  39.         $loop->add($lEvent);
  40.         //$GLOBALS['test'] = $lEvent;
  41.  
  42.     }
  43.  
  44.     public function handleEvent() {
  45.  
  46.         echo fgets($this->handle);
  47.  
  48.     }
  49.  
  50. }
  51.  
  52. $loop = new Loop();
  53. $stream = new ReadableStream(STDIN, $loop);
  54.  
  55. $loop->loop();
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement