Skip to content

Commit 7482a6f

Browse files
committed
Client::sendAsync() no longer throws an exception if a request is canceled multiple times by the returned value of a callback;
Fixed Util::count() example; Fixed Communicator::decodeLength() and Communicator::_decodeLength() docs to include "double".
1 parent 9cdb61e commit 7482a6f

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

RELEASE-1.0.0b6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Util stuff, mostly.
2121
* Util::find() now works even when the underlying Client streams responses.
2222
* Util::move()'s second argument $destination is now optional, and without it (or if set to NULL), the item is moved at the bottom of the menu.
2323
* Client::login() consumes the !done or !fatal response even when called on an already logged in connection.
24+
* Client::sendAsync() no longer throws an exception if a request is canceled multiple times by the returned value of a callback.
2425
* The console now checks whether PEAR2_CommandLine is installed, ensuring better error messages when this package is installed without its optional dependencies.

examples/Util/count.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
echo $util->count() . "\n";
1616

1717
//Count only disabled ARP items
18-
echo $util->count(COUNT_NORMAL, RouterOS\Query::where('disabled', 'true')) . "\n";
18+
echo $util->count(RouterOS\Query::where('disabled', 'true')) . "\n";

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,13 @@ protected function dispatchNextResponse($sTimeout = 0, $usTimeout = 0)
833833
if ('' != $tag) {
834834
if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
835835
if ($this->callbacks[$tag]($response, $this)) {
836-
$this->cancelRequest($tag);
836+
try {
837+
$this->cancelRequest($tag);
838+
} catch (DataFlowException $e) {
839+
if ($e->getCode() !== DataFlowException::CODE_UNKNOWN_REQUEST) {
840+
throw $e;
841+
}
842+
}
837843
} elseif ($isLastForRequest) {
838844
unset($this->callbacks[$tag]);
839845
}

src/PEAR2/Net/RouterOS/Communicator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,8 @@ public function getNextWordAsStream()
624624
* @param T\Stream $trans The transmitter from which to decode the length of
625625
* the incoming message.
626626
*
627-
* @return int The decoded length.
627+
* @return int|double The decoded length.
628+
* Is of type "double" only for values above "2 << 31".
628629
*/
629630
public static function decodeLength(T\Stream $trans)
630631
{
@@ -649,7 +650,8 @@ public static function decodeLength(T\Stream $trans)
649650
* @param T\Stream $trans The transmitter from which to decode the length of
650651
* the incoming message.
651652
*
652-
* @return int The decoded length.
653+
* @return int|double The decoded length.
654+
* Is of type "double" only for values above "2 << 31".
653655
*/
654656
private static function _decodeLength(T\Stream $trans)
655657
{

tests/Client/Safe.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,25 @@ public function testSendAsyncAndInvalidCancel()
301301
'Improper active request count after cancel test.'
302302
);
303303
}
304+
305+
public function testSendAsyncAndMultipleCancelFromCallback()
306+
{
307+
$printRequest = new Request('/queue/simple/print');
308+
$printRequest->setArgument('follow')
309+
->setArgument('.proplist')
310+
->setTag('f');
311+
$repliesCount = 0;
312+
$this->object->sendAsync(
313+
$printRequest,
314+
function () use (&$repliesCount) {
315+
$repliesCount++;
316+
return 1 < $repliesCount && $repliesCount < 6;
317+
}
318+
);
319+
$this->object->loop();
320+
$this->assertGreaterThanOrEqual(5, $repliesCount);
321+
$this->assertFalse($this->object->isRequestActive('f'));
322+
}
304323

305324
public function testSendAsyncAndFullExtract()
306325
{

0 commit comments

Comments
 (0)