Skip to content

Commit e8d8e01

Browse files
committed
Merge pull request #8 from clue/fix-hhvm
Fix hhvm
2 parents 6972a55 + e206d70 commit e8d8e01

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: php
22
php:
33
- 5.4
44
- 5.3
5+
- hhvm
56
before_script:
67
- composer install --dev --prefer-source --no-interaction
78
script:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ you spot any mistakes.
2020
* Fix: Typo in `Socket\React\Stream\Server` that passed null (thanks @cboden!)
2121
* Fix: End connection if reading from stream socket fails
2222
([#7](https://github.com/clue/socket-react/pull/7))
23+
* Fix: Compatibility with hhvm
24+
([#8](https://github.com/clue/socket-react/pull/8))
2325

2426
## 0.1.0 (2013-04-18)
2527

Socket/React/EventLoop/SocketSelectLoop.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public function __construct()
2929

3030
public function addReadStream($stream, $listener)
3131
{
32-
if (get_resource_type($stream) !== 'Socket') {
33-
throw new InvalidArgumentException('Socket loop only accepts resources of type "Socket", but "' . get_resource_type($stream) .'" given');
34-
}
32+
$this->assertStream($stream);
3533

3634
$id = (int) $stream;
3735

@@ -43,9 +41,7 @@ public function addReadStream($stream, $listener)
4341

4442
public function addWriteStream($stream, $listener)
4543
{
46-
if (get_resource_type($stream) !== 'Socket') {
47-
throw new InvalidArgumentException('Socket loop only accepts resources of type "Socket", but "' . get_resource_type($stream) .'" given');
48-
}
44+
$this->assertStream($stream);
4945

5046
$id = (int) $stream;
5147

@@ -194,4 +190,19 @@ public function stop()
194190
{
195191
$this->running = false;
196192
}
193+
194+
private function assertStream($stream)
195+
{
196+
static $checked = array();
197+
$type = get_resource_type($stream);
198+
if (is_resource($stream) && !isset($checked[$type])) {
199+
$except = array($stream);
200+
$null = null;
201+
$checked[$type] = (@socket_select($null, $null, $except, 0) !== false);
202+
}
203+
204+
if (!$checked[$type]) {
205+
throw new InvalidArgumentException('Socket loop only accepts resources of type "Socket", but "' . $type .'" given');
206+
}
207+
}
197208
}

tests/EventLoop/AbstractLoopTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,4 @@ public function testClientTcp4()
4646

4747
$this->loop->run();
4848
}
49-
50-
/**
51-
* @expectedException InvalidArgumentException
52-
*/
53-
public function testAddReadStreamInvalid()
54-
{
55-
$stream = fopen('php://temp', 'r+');
56-
57-
$this->loop->addReadStream($stream, null);
58-
}
59-
60-
/**
61-
* @expectedException InvalidArgumentException
62-
*/
63-
public function testAddWriteStreamInvalid()
64-
{
65-
$stream = fopen('php://temp', 'r+');
66-
67-
$this->loop->addWriteStream($stream, null);
68-
}
6949
}

0 commit comments

Comments
 (0)