X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=tests%2Fclient029.phpt;h=a95508c27bc47974817ffe5c4c68a28fa9e193f2;hp=70f1005e6a3114f19800484d0a409584948c2c79;hb=a8efa8d8c35f4ba392962cac2bd49e872717a058;hpb=c55db20a130d729ca8747346c5e5ab9fb52fd89d diff --git a/tests/client029.phpt b/tests/client029.phpt index 70f1005..a95508c 100644 --- a/tests/client029.phpt +++ b/tests/client029.phpt @@ -4,45 +4,44 @@ client curl user handler ---XFAIL-- -ext-ev leaks --FILE-- evbase = $evbase; $this->client = $client; } - function init(callable $run) { + function init($run) { $this->run = $run; } function timer(int $timeout_ms) { echo "T"; if (isset($this->timeout)) { - $this->timeout->set($timeout_ms/1000, 0); - $this->timeout->start(); + $this->timeout->add($timeout_ms/1000); } else { - $this->timeout = new EvTimer($timeout_ms/1000, 0, function() { + $this->timeout = Event::timer($this->evbase, function() { if (!call_user_func($this->run, $this->client)) { if ($this->timeout) { - $this->timeout->stop(); + $this->timeout->del(); $this->timeout = null; } } }); + $this->timeout->add($timeout_ms/1000); } } @@ -55,7 +54,7 @@ class UserHandler implements http\Client\Curl\User case self::POLL_REMOVE: if (isset($this->ios[(int) $socket])) { echo "U"; - $this->ios[(int) $socket]->stop(); + $this->ios[(int) $socket]->del(); unset($this->ios[(int) $socket]); } break; @@ -63,44 +62,50 @@ class UserHandler implements http\Client\Curl\User default: $ev = 0; if ($action & self::POLL_IN) { - $ev |= Ev::READ; + $ev |= Event::READ; } if ($action & self::POLL_OUT) { - $ev |= Ev::WRITE; + $ev |= Event::WRITE; } if (isset($this->ios[(int) $socket])) { - $this->ios[(int) $socket]->set($socket, $ev); + $this->ios[(int) $socket]->set($this->evbase, + $socket, $ev, $this->onEvent($socket)); } else { - $this->ios[(int) $socket] = new EvIo($socket, $ev, function($watcher, $events) use($socket) { - $action = 0; - if ($events & Ev::READ) { - $action |= self::POLL_IN; - } - if ($events & Ev::WRITE) { - $action |= self::POLL_OUT; - } - if (!call_user_func($this->run, $this->client, $socket, $action)) { - if ($this->timeout) { - $this->timeout->stop(); - $this->timeout = null; - } - } - }); + $this->ios[(int) $socket] = new Event($this->evbase, + $socket, $ev, $this->onEvent($socket)); } break; } } + function onEvent($socket) { + return function($watcher, $events) use($socket) { + $action = 0; + if ($events & Ev::READ) { + $action |= self::POLL_IN; + } + if ($events & Ev::WRITE) { + $action |= self::POLL_OUT; + } + if (!call_user_func($this->run, $this->client, $socket, $action)) { + if ($this->timeout) { + $this->timeout->del(); + $this->timeout = null; + } + } + }; + } + function once() { - throw new BadMethodCallException("this test uses Ev::run()"); + throw new BadMethodCallException("this test uses EventBase::loop()"); } function wait(int $timeout_ms = null) { - throw new BadMethodCallException("this test uses Ev::run()"); + throw new BadMethodCallException("this test uses EventBase::loop()"); } function send() { - throw new BadMethodCallException("this test uses Ev::run()"); + throw new BadMethodCallException("this test uses EventBase::loop()"); } } @@ -108,19 +113,20 @@ class UserHandler implements http\Client\Curl\User include "helper/server.inc"; server("proxy.inc", function($port) { + $evbase = new EventBase; $client = new http\Client; $client->configure([ - "use_eventloop" => new UserHandler($client) + "use_eventloop" => new UserHandler($client, $evbase) ]); $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) { var_dump($r->getResponseCode()); }); - Ev::run(); + $evbase->loop(); }); ?> ===DONE=== --EXPECTREGEX-- Test -T[ST]+U+int\(200\) +T*[ST]+U+T*int\(200\) ===DONE===