Skip to content

Commit 1d94c65

Browse files
committed
Run tests on PHP 8.4 and update test environment
1 parent da2e173 commit 1d94c65

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ on:
77
jobs:
88
PHPUnit:
99
name: PHPUnit (PHP ${{ matrix.php }})
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-24.04
1111
strategy:
1212
matrix:
1313
php:
14+
- 8.4
1415
- 8.3
1516
- 8.2
1617
- 8.1
@@ -38,7 +39,7 @@ jobs:
3839

3940
PHPUnit-hhvm:
4041
name: PHPUnit (HHVM)
41-
runs-on: ubuntu-22.04
42+
runs-on: ubuntu-24.04
4243
continue-on-error: true
4344
steps:
4445
- uses: actions/checkout@v4

src/Client.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Client
2525
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
2626
* given event loop instance.
2727
*
28-
* @param ?LoopInterface $loop
29-
* @param ?MulticastFactory $multicast
28+
* @param LoopInterface|null $loop
29+
* @param MulticastFactory|null $multicast
3030
*/
3131
public function __construct(LoopInterface $loop = null, MulticastFactory $multicast = null)
3232
{
@@ -46,29 +46,37 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4646
$socket = $this->multicast->createSender();
4747
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
4848

49-
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred) {
50-
$deferred->resolve();
51-
$socket->close();
52-
});
49+
// Use a variable to track the timer outside closures
50+
$timer = null;
5351

52+
// Create the deferred with the canceller function
5453
$loop = $this->loop;
55-
$deferred = new Deferred(function () use ($socket, &$timer, $loop) {
54+
$canceller = function () use ($socket, &$timer, $loop) {
5655
// canceling resulting promise cancels timer and closes socket
57-
$loop->cancelTimer($timer);
56+
if ($timer !== null) {
57+
$loop->cancelTimer($timer);
58+
}
5859
$socket->close();
5960
throw new RuntimeException('Cancelled');
60-
});
61+
};
6162

62-
$that = $this;
63-
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
64-
$message = $that->parseMessage($data, $remote);
63+
$deferred = new Deferred($canceller);
6564

66-
$deferred->progress($message);
65+
// Now set up the timer with reference to our deferred
66+
$timer = $this->loop->addTimer($mx, function() use ($socket, $deferred) {
67+
$deferred->resolve();
68+
$socket->close();
6769
});
6870

69-
$socket->send($data, self::ADDRESS);
71+
$that = $this;
72+
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
73+
$message = $that->parseMessage($data, $remote);
74+
$deferred->progress($message);
75+
});
76+
77+
$socket->send($data, self::ADDRESS);
7078

71-
return $deferred->promise();
79+
return $deferred->promise();
7280
}
7381

7482
/** @internal */

0 commit comments

Comments
 (0)