Created
January 18, 2013 22:59
-
-
Save clue/4569425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class SocketStreamAdapter extends EventEmitter | |
| { | |
| const DELAY_TICK = 0.01; | |
| const DURATION_TICK = 0; | |
| protected $loop; | |
| protected $socket; | |
| protected $tid = null; | |
| public function __construct(LoopInterface $loop, $socket) | |
| { | |
| $this->loop = $loop; | |
| $this->socket = $socket; | |
| $this->resume(); | |
| } | |
| public function resume() | |
| { | |
| $this->tid = $this->loop->addPeriodicTimer(self::DELAY_TICK, array($this, 'tick')); | |
| } | |
| public function pause() | |
| { | |
| $this->loop->removeTimer($this->tid); | |
| $this->tid = null; | |
| } | |
| // a polling tick function | |
| public function tick() | |
| { | |
| $r = array($this->socket); | |
| socket_select($r, $w=null, $e=null, 0, self::DURATION_TICK * 1000000); | |
| if ($r) { | |
| $that->emit('ready', array($this->socket, $this)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment