2 client curl user handler
16 class UserHandler implements http\Client\Curl\User
24 function __construct(http\Client $client) {
25 $this->client = $client;
32 function timer(int $timeout_ms) {
34 if (isset($this->timeout)) {
35 $this->timeout->set($timeout_ms/1000, 0);
36 $this->timeout->start();
38 $this->timeout = new EvTimer($timeout_ms/1000, 0, function() {
39 if (!call_user_func($this->run, $this->client)) {
41 $this->timeout->stop();
42 $this->timeout = null;
49 function socket($socket, int $action) {
55 case self::POLL_REMOVE:
56 if (isset($this->ios[(int) $socket])) {
58 $this->ios[(int) $socket]->stop();
59 unset($this->ios[(int) $socket]);
65 if ($action & self::POLL_IN) {
68 if ($action & self::POLL_OUT) {
71 if (isset($this->ios[(int) $socket])) {
72 $this->ios[(int) $socket]->set($socket, $ev);
74 $this->ios[(int) $socket] = new EvIo($socket, $ev, function($watcher, $events) use($socket) {
76 if ($events & Ev::READ) {
77 $action |= self::POLL_IN;
79 if ($events & Ev::WRITE) {
80 $action |= self::POLL_OUT;
82 if (!call_user_func($this->run, $this->client, $socket, $action)) {
84 $this->timeout->stop();
85 $this->timeout = null;
95 throw new BadMethodCallException("this test uses Ev::run()");
98 function wait(int $timeout_ms = null) {
99 throw new BadMethodCallException("this test uses Ev::run()");
103 throw new BadMethodCallException("this test uses Ev::run()");
108 include "helper/server.inc";
110 server("proxy.inc", function($port) {
111 $client = new http\Client;
113 "use_eventloop" => new UserHandler($client)
115 $client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) {
116 var_dump($r->getResponseCode());