4 class EvHandler
implements http\Client\Curl\User
11 function __construct(http\Client
$client) {
12 $this->client
= $client;
19 function timer(int $timeout_ms) {
20 if (isset($this->timeout
)) {
21 $this->timeout
->set($timeout_ms/1000, 0);
22 $this->timeout
->start();
24 $this->timeout
= new EvTimer($timeout_ms/1000, 0, function() {
25 if (!call_user_func($this->run
, $this->client
)) {
27 $this->timeout
->stop();
28 $this->timeout
= null;
35 function socket($socket, int $action) {
39 case self
::POLL_REMOVE
:
41 if (isset($this->ios
[(int) $socket])) {
42 $this->ios
[(int) $socket]->stop();
43 unset($this->ios
[(int) $socket]);
48 if ($action & self
::POLL_IN
) {
51 if ($action & self
::POLL_OUT
) {
54 if (isset($this->ios
[(int) $socket])) {
55 $this->ios
[(int) $socket]->set($socket, $ev);
57 $this->ios
[(int) $socket] = new EvIo($socket, $ev, function($watcher, $events) use($socket) {
59 if ($events & Ev
::READ
) {
60 $action |
= self
::POLL_IN
;
62 if ($events & Ev
::WRITE
) {
63 $action |
= self
::POLL_OUT
;
65 if (!call_user_func($this->run
, $this->client
, $socket, $action)) {
67 $this->timeout
->stop();
68 $this->timeout
= null;
79 Ev
::run(EV
::RUN_NOWAIT
);
81 function wait(int $timeout_ms = null) {
83 Ev
::run(EV
::RUN_ONCE
);