File: client029.phpt

package info (click to toggle)
php-pecl-http 3.1.0%2B2.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,060 kB
  • ctags: 3,725
  • sloc: ansic: 37,486; xml: 818; php: 635; pascal: 164; makefile: 2
file content (126 lines) | stat: -rw-r--r-- 2,495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--TEST--
client curl user handler
--SKIPIF--
<?php 
include "skipif.inc";
skip_client_test();
_ext("ev");

?> 
--XFAIL--
ext-ev leaks
--FILE--
<?php 
echo "Test\n";

class UserHandler implements http\Client\Curl\User
{
	private $client;
	private $run;
	private $ios = [];
	private $timeout;


	function __construct(http\Client $client) {
		$this->client = $client;
	}
	
	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();
		} else {
			$this->timeout = new EvTimer($timeout_ms/1000, 0, function() {
				if (!call_user_func($this->run, $this->client)) {
					if ($this->timeout) {
						$this->timeout->stop();
						$this->timeout = null;
					}
				}
			});
		}
	}
	
	function socket($socket, int $action) {
		echo "S";
		
		switch ($action) {
		case self::POLL_NONE:
			break;
		case self::POLL_REMOVE:
			if (isset($this->ios[(int) $socket])) {
				echo "U";
				$this->ios[(int) $socket]->stop();
				unset($this->ios[(int) $socket]);
			}
			break;
			
		default:
			$ev = 0;
			if ($action & self::POLL_IN) {
				$ev |= Ev::READ;
			}
			if ($action & self::POLL_OUT) {
				$ev |= Ev::WRITE;
			}
			if (isset($this->ios[(int) $socket])) {
				$this->ios[(int) $socket]->set($socket, $ev);
			} 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;
						}
					}
				});
			}
			break;
		}
	}
	
	function once() {
		throw new BadMethodCallException("this test uses Ev::run()");
	}
	
	function wait(int $timeout_ms = null) {
		throw new BadMethodCallException("this test uses Ev::run()");
	}
	
	function send() {
		throw new BadMethodCallException("this test uses Ev::run()");
	}
}


include "helper/server.inc";

server("proxy.inc", function($port) {
	$client = new http\Client;
	$client->configure([
			"use_eventloop" => new UserHandler($client)
	]);
	$client->enqueue(new http\Client\Request("GET", "http://localhost:$port/"), function($r) {
		var_dump($r->getResponseCode());
	});
	Ev::run();
});

?>
===DONE===
--EXPECTREGEX--
Test
T[ST]+U+int\(200\)
===DONE===