Skip to content

Commit 6d9743d

Browse files
committed
add libzmq 4.1.7 support
This adds support for the socks proxy api.php update created with DocThor, see DEVELOPERS.md
1 parent 7ea3905 commit 6d9743d

File tree

4 files changed

+187
-20
lines changed

4 files changed

+187
-20
lines changed

DEVELOPERS.md

-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ line.
3636

3737
```shell
3838
git clone https://github.com/SegFaulty/DocThor
39-
php DocThor/DocThor.php --sourceDir=./ zmq
4039
php -d extension=modules/zmq.so DocThor.php --sourceDir=./ zmq
4140
```

api.php

+150-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* zmq-API v@PACKAGE_VERSION@ Docs build by DocThor [2016-02-01]
3+
* zmq-API v@PACKAGE_VERSION@ Docs build by DocThor [2020-02-16]
44
* @package zmq
55
*/
66

@@ -30,18 +30,22 @@ class ZMQ {
3030
const MODE_NOBLOCK = 1;
3131
const MODE_DONTWAIT = 1;
3232
const ERR_INTERNAL = -99;
33-
const ERR_EAGAIN = 35;
34-
const ERR_ENOTSUP = 45;
33+
const ERR_EAGAIN = 11;
34+
const ERR_ENOTSUP = 95;
3535
const ERR_EFSM = 156384763;
3636
const ERR_ETERM = 156384765;
37-
const LIBZMQ_VER = '4.1.4';
38-
const LIBZMQ_VERSION = '4.1.4';
39-
const LIBZMQ_VERSION_ID = 40104;
37+
const LIBZMQ_VER = '4.1.7';
38+
const LIBZMQ_VERSION = '4.1.7';
39+
const LIBZMQ_VERSION_ID = 40107;
4040
const LIBZMQ_VERSION_MAJOR = 4;
4141
const LIBZMQ_VERSION_MINOR = 1;
42-
const LIBZMQ_VERSION_PATCH = 4;
42+
const LIBZMQ_VERSION_PATCH = 7;
4343
const SOCKOPT_TOS = 57;
4444
const SOCKOPT_ROUTER_HANDOVER = 56;
45+
const SOCKOPT_CONNECT_RID = 61;
46+
const SOCKOPT_HANDSHAKE_IVL = 66;
47+
const SOCKOPT_SOCKS_PROXY = 68;
48+
const SOCKOPT_XPUB_NODROP = 69;
4549
const SOCKOPT_ROUTER_MANDATORY = 33;
4650
const SOCKOPT_PROBE_ROUTER = 51;
4751
const SOCKOPT_REQ_RELAXED = 53;
@@ -109,6 +113,11 @@ class ZMQ {
109113
const EVENT_DISCONNECTED = 512;
110114
const EVENT_MONITOR_STOPPED = 1024;
111115
const EVENT_ALL = 65535;
116+
/**
117+
* A monotonic clock
118+
*
119+
* @return integer
120+
*/
112121
public function clock() {}
113122
public function z85encode($data) {}
114123
public function z85decode($data) {}
@@ -118,55 +127,177 @@ public function curvekeypair() {}
118127
* @package zmq
119128
*/
120129
class ZMQContext {
121-
public function __construct($io_threads = 1, $persistent = true) {}
130+
/**
131+
* Build a new ZMQContext object
132+
*
133+
* @param integer $io_threads
134+
* @param boolean $is_persistent
135+
* @return ZMQContext
136+
*/
137+
public function __construct($io_threads="", $persistent="") {}
138+
/**
139+
* Acquires a handle to the request global context
140+
*
141+
* @return ZMQContext
142+
*/
122143
public function acquire() {}
123144
public function getsocketcount() {}
124145
public function getsocket($type, $dsn, $on_new_socket="") {}
125146
public function ispersistent() {}
147+
/**
148+
* Set a context option
149+
*
150+
* @param int $option
151+
* @param int $value
152+
* @return ZMQContext
153+
*/
126154
public function setOpt($option, $value) {}
155+
/**
156+
* Set a context option
157+
*
158+
* @param int $option
159+
* @return ZMQContext
160+
*/
127161
public function getOpt($option) {}
128162
}
129163
/**
130164
* @package zmq
131165
*/
132166
class ZMQSocket {
133-
public function __construct(ZMQContext $ZMQContext, $type, $persistent_id=null, $on_new_socket=null) {}
134-
public function send($message, $mode=0) {}
167+
/**
168+
* Build a new ZMQSocket object
169+
*
170+
* @param ZMQContext $context
171+
* @param integer $type
172+
* @param string $persistent_id
173+
* @param callback $on_new_socket
174+
* @return ZMQSocket
175+
*/
176+
public function __construct(ZMQContext $ZMQContext, $type, $persistent_id="", $on_new_socket="") {}
177+
/**
178+
* Send a message. Return true if message was sent and false on EAGAIN
179+
*
180+
* @param string $message
181+
* @param integer $flags
182+
* @return ZMQSocket
183+
*/
184+
public function send($message, $mode="") {}
135185
public function recv($mode="") {}
136-
public function sendmulti($message, $mode=0) {}
137-
public function recvmulti($mode=0) {}
138-
public function bind($dsn, $force=false) {}
139-
public function connect($dsn, $force=false) {}
140-
public function monitor($dsn, $events=ZMQ::EVENT_ALL) {}
141-
public function recvevent($flags=0) {}
186+
/**
187+
* Send a multipart message. Return true if message was sent and false on EAGAIN
188+
*
189+
* @param arrays $messages
190+
* @param integer $flags
191+
* @return ZMQSocket
192+
*/
193+
public function sendmulti($message, $mode="") {}
194+
public function recvmulti($mode="") {}
195+
/**
196+
* Bind the socket to an endpoint
197+
*
198+
* @param string $dsn
199+
* @param boolean $force
200+
* @return ZMQSocket
201+
*/
202+
public function bind($dsn, $force="") {}
203+
/**
204+
* Connect the socket to an endpoint
205+
*
206+
* @param string $dsn
207+
* @param boolean $force
208+
* @return ZMQSocket
209+
*/
210+
public function connect($dsn, $force="") {}
211+
public function monitor($dsn, $events="") {}
212+
public function recvevent($flags="") {}
213+
/**
214+
* Unbind the socket from an endpoint
215+
*
216+
* @param string $dsn
217+
* @return ZMQSocket
218+
*/
142219
public function unbind($dsn) {}
220+
/**
221+
* Disconnect the socket from an endpoint
222+
*
223+
* @param string $dsn
224+
* @return ZMQSocket
225+
*/
143226
public function disconnect($dsn) {}
144227
public function setsockopt($key, $value) {}
145228
public function getendpoints() {}
146229
public function getsockettype() {}
147230
public function ispersistent() {}
148231
public function getpersistentid() {}
149232
public function getsockopt($key) {}
150-
public function sendmsg($message, $mode=0) {}
151-
public function recvmsg($mode=0) {}
233+
public function sendmsg($message, $mode="") {}
234+
public function recvmsg($mode="") {}
152235
}
153236
/**
154237
* @package zmq
155238
*/
156239
class ZMQPoll {
240+
/**
241+
* Add a ZMQSocket object into the pollset
242+
*
243+
* @param ZMQSocket $object
244+
* @param integer $events
245+
* @return integer
246+
*/
157247
public function add($entry, $type) {}
248+
/**
249+
* Poll the sockets
250+
*
251+
* @param array $readable
252+
* @param array $writable
253+
* @param integer $timeout
254+
* @return integer
255+
*/
158256
public function poll(&$readable, &$writable, $timeout="") {}
159257
public function getlasterrors() {}
258+
/**
259+
* Remove item from poll set
260+
*
261+
* @param mixed $item
262+
* @return boolean
263+
*/
160264
public function remove($remove) {}
265+
/**
266+
* Returns the number of items in the set
267+
*
268+
* @return integer
269+
*/
161270
public function count() {}
271+
/**
272+
* Clear the pollset
273+
*
274+
* @return ZMQPoll
275+
*/
162276
public function clear() {}
277+
/**
278+
* Clear the pollset
279+
*
280+
* @return array
281+
*/
163282
public function items() {}
164283
}
165284
/**
166285
* @package zmq
167286
*/
168287
class ZMQDevice {
169-
public function __construct(ZMQSocket $frontend, ZMQSocket $backend, ZMQSocket $capture=null) {}
288+
/**
289+
* Construct a device
290+
*
291+
* @param ZMQSocket $frontend
292+
* @param ZMQSocket $backend
293+
* @return void
294+
*/
295+
public function __construct(ZMQSocket $frontend, ZMQSocket $backend, ZMQSocket $capture="") {}
296+
/**
297+
* Start a device
298+
*
299+
* @return void
300+
*/
170301
public function run() {}
171302
public function setidlecallback($idle_callback, $timeout, $user_data="") {}
172303
public function setidletimeout($timeout) {}

package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<file name="052-pthreads.phpt" role="test" />
132132
<file name="053-z85.phpt" role="test" />
133133
<file name="054-curvekeypair.phpt" role="test" />
134+
<file name="055-socks-proxy.phpt" role="test" />
134135
<file name="bug_gh_156.phpt" role="test" />
135136
<file name="bug_gh_43.phpt" role="test" />
136137
<file name="bug_gh_49.phpt" role="test" />

tests/055-socks-proxy.phpt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Test socks proxy
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . '/skipif.inc');
6+
if(!fsockopen('127.0.0.1', 5557, $errCode, $errStr, 0.1))
7+
die ('skip test requires local SOCKS5 proxy on port 5557');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
// local socks proxy can be enabled by running sshd and also running
13+
// ssh -D 5557 -C -N root@localhost
14+
15+
include dirname(__FILE__) . '/zeromq_test_helper.inc';
16+
17+
$context = new ZMQContext();
18+
$server = $context->getSocket(ZMQ::SOCKET_REP, null)
19+
->bind('tcp://127.0.0.1:5556');
20+
$context = new ZMQContext();
21+
$client = $context->getSocket(ZMQ::SOCKET_REQ, null);
22+
$client->setSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY, "localhost:5557");
23+
$client ->connect('tcp://127.0.0.1:5556');
24+
25+
$client->sendmsg("Hello world!");
26+
27+
$message = $server->recvmsg();
28+
var_dump($message);
29+
$server->sendmsg($message);
30+
31+
$message = $client->recvmsg();
32+
var_dump($message);
33+
34+
--EXPECT--
35+
string(12) "Hello world!"
36+
string(12) "Hello world!"

0 commit comments

Comments
 (0)