Skip to content

Commit 44e059e

Browse files
committed
Merge remote-tracking branch 'origin/master' into no-next-tick
2 parents 1a4c7ea + 0ba8aa3 commit 44e059e

17 files changed

Lines changed: 256 additions & 121 deletions

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ php:
44
- 5.4
55
- 5.5
66
- 5.6
7+
- 7.0
78
- hhvm
8-
- hhvm-nightly
9-
10-
matrix:
11-
allow_failures:
12-
- php: hhvm
13-
- php: hhvm-nightly
14-
fast_finish: true
159

1610
install: ./travis-init.sh
1711

1812
script:
19-
- phpunit --coverage-text
13+
- ./vendor/bin/phpunit --coverage-text

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 0.5.0 (xxxx-xx-xx)
4+
5+
* BC break: Remove `LoopInterface::tick()` (@jsor, #72)
6+
7+
## 0.4.2 (2016-03-07)
8+
9+
* Bug fix: No longer error when signals sent to StreamSelectLoop
10+
* Support HHVM and PHP7 (@ondrejmirtes, @cebe)
11+
* Feature: Added support for EventConfig for ExtEventLoop (@steverhoades)
12+
* Bug fix: Fixed an issue loading loop extension libs via autoloader (@czarpino)
13+
314
## 0.4.1 (2014-04-13)
415

516
* Bug fix: null timeout in StreamSelectLoop causing 100% CPU usage (@clue)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Here is an async HTTP server built with just the event loop.
4949
fclose($conn);
5050
$loop->removeStream($conn);
5151
} else {
52-
$data = substr($data, 0, $written);
52+
$data = substr($data, $written);
5353
}
5454
});
5555
});

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"require": {
77
"php": ">=5.4.0"
88
},
9+
"require-dev": {
10+
"phpunit/phpunit": "~4.8"
11+
},
912
"suggest": {
1013
"ext-libevent": ">=0.1.0",
1114
"ext-event": "~1.0",
@@ -15,10 +18,5 @@
1518
"psr-4": {
1619
"React\\EventLoop\\": "src"
1720
}
18-
},
19-
"extra": {
20-
"branch-alias": {
21-
"dev-master": "0.5-dev"
22-
}
2321
}
2422
}

src/ExtEventLoop.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,6 @@ public function futureTick(callable $listener)
158158
$this->futureTickQueue->add($listener);
159159
}
160160

161-
/**
162-
* {@inheritdoc}
163-
*/
164-
public function tick()
165-
{
166-
$this->futureTickQueue->tick();
167-
168-
// @-suppression: https://github.com/reactphp/react/pull/234#discussion-diff-7759616R226
169-
@$this->eventBase->loop(EventBase::LOOP_ONCE | EventBase::LOOP_NONBLOCK);
170-
}
171-
172161
/**
173162
* {@inheritdoc}
174163
*/
@@ -279,7 +268,7 @@ private function unsubscribeStreamEvent($stream, $flag)
279268
*/
280269
private function createTimerCallback()
281270
{
282-
$this->timerCallback = function ($_, $_, $timer) {
271+
$this->timerCallback = function ($_, $__, $timer) {
283272
call_user_func($timer->getCallback(), $timer);
284273

285274
if (!$timer->isPeriodic() && $this->isTimerActive($timer)) {

src/LibEvLoop.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,6 @@ public function futureTick(callable $listener)
162162
$this->futureTickQueue->add($listener);
163163
}
164164

165-
/**
166-
* {@inheritdoc}
167-
*/
168-
public function tick()
169-
{
170-
$this->futureTickQueue->tick();
171-
172-
$this->loop->run(EventLoop::RUN_ONCE | EventLoop::RUN_NOWAIT);
173-
}
174-
175165
/**
176166
* {@inheritdoc}
177167
*/

src/LibEventLoop.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,6 @@ public function futureTick(callable $listener)
166166
$this->futureTickQueue->add($listener);
167167
}
168168

169-
/**
170-
* {@inheritdoc}
171-
*/
172-
public function tick()
173-
{
174-
$this->futureTickQueue->tick();
175-
176-
event_base_loop($this->eventBase, EVLOOP_ONCE | EVLOOP_NONBLOCK);
177-
}
178-
179169
/**
180170
* {@inheritdoc}
181171
*/
@@ -283,7 +273,7 @@ private function unsubscribeStreamEvent($stream, $flag)
283273
*/
284274
private function createTimerCallback()
285275
{
286-
$this->timerCallback = function ($_, $_, $timer) {
276+
$this->timerCallback = function ($_, $__, $timer) {
287277
call_user_func($timer->getCallback(), $timer);
288278

289279
// Timer already cancelled ...

src/LoopInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ public function isTimerActive(TimerInterface $timer);
9494
*/
9595
public function futureTick(callable $listener);
9696

97-
/**
98-
* Perform a single iteration of the event loop.
99-
*/
100-
public function tick();
101-
10297
/**
10398
* Run the event loop until there are no more tasks to perform.
10499
*/

src/StreamSelectLoop.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,6 @@ public function futureTick(callable $listener)
137137
$this->futureTickQueue->add($listener);
138138
}
139139

140-
/**
141-
* {@inheritdoc}
142-
*/
143-
public function tick()
144-
{
145-
$this->futureTickQueue->tick();
146-
147-
$this->timers->tick();
148-
149-
$this->waitForStreamActivity(0);
150-
}
151-
152140
/**
153141
* {@inheritdoc}
154142
*/
@@ -203,7 +191,12 @@ private function waitForStreamActivity($timeout)
203191
$read = $this->readStreams;
204192
$write = $this->writeStreams;
205193

206-
$this->streamSelect($read, $write, $timeout);
194+
$available = $this->streamSelect($read, $write, $timeout);
195+
if (false === $available) {
196+
// if a system call has been interrupted,
197+
// we cannot rely on it's outcome
198+
return;
199+
}
207200

208201
foreach ($read as $stream) {
209202
$key = (int) $stream;
@@ -230,17 +223,19 @@ private function waitForStreamActivity($timeout)
230223
* @param array &$write An array of write streams to select upon.
231224
* @param integer|null $timeout Activity timeout in microseconds, or null to wait forever.
232225
*
233-
* @return integer The total number of streams that are ready for read/write.
226+
* @return integer|false The total number of streams that are ready for read/write.
227+
* Can return false if stream_select() is interrupted by a signal.
234228
*/
235229
protected function streamSelect(array &$read, array &$write, $timeout)
236230
{
237231
if ($read || $write) {
238232
$except = null;
239233

240-
return stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
234+
// suppress warnings that occur, when stream_select is interrupted by a signal
235+
return @stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
241236
}
242237

243-
usleep($timeout);
238+
$timeout && usleep($timeout);
244239

245240
return 0;
246241
}

src/Timer/Timers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getTime()
3030
public function add(TimerInterface $timer)
3131
{
3232
$interval = $timer->getInterval();
33-
$scheduledAt = $interval + $this->getTime();
33+
$scheduledAt = $interval + microtime(true);
3434

3535
$this->timers->attach($timer, $scheduledAt);
3636
$this->scheduler->insert($timer, -$scheduledAt);

0 commit comments

Comments
 (0)