Skip to content

add EventLoop support for >= v1.0 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
],
"require": {
"php": ">=5.3",
"clue/socket-raw": "1.* | 0.1.*",
"evenement/evenement": "1.*",
"react/event-loop": ">=0.2, <0.4",
"react/promise": "1.*",
"react/stream": ">=0.2, <0.4",
"react/socket": ">=0.2, <0.4",
"react/datagram": "~1.0"
"clue/socket-raw": "^1.0",
"evenement/evenement": "^3.0",
"react/event-loop": "^1.0",
"react/promise": "^2.0",
"react/stream": "^1.0",
"react/socket": "^1.0",
"react/datagram": "^1.0",
"ext-sockets": "*"
},
"autoload": {
"psr-4": {"Socket\\React\\": "src"}
Expand Down
49 changes: 38 additions & 11 deletions src/EventLoop/SocketSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use React\EventLoop\LoopInterface;
use React\EventLoop\Timer\Timer;
use React\EventLoop\Timer\TimerInterface;
use React\EventLoop\TimerInterface;
use React\EventLoop\Timer\Timers;
use InvalidArgumentException;

Expand All @@ -31,7 +31,7 @@ public function addReadStream($stream, $listener)
{
$this->assertStream($stream);

$id = (int) $stream;
$id = (int)$stream;

if (!isset($this->readStreams[$id])) {
$this->readStreams[$id] = $stream;
Expand All @@ -43,7 +43,7 @@ public function addWriteStream($stream, $listener)
{
$this->assertStream($stream);

$id = (int) $stream;
$id = (int)$stream;

if (!isset($this->writeStreams[$id])) {
$this->writeStreams[$id] = $stream;
Expand All @@ -53,7 +53,7 @@ public function addWriteStream($stream, $listener)

public function removeReadStream($stream)
{
$id = (int) $stream;
$id = (int)$stream;

unset(
$this->readStreams[$id],
Expand All @@ -63,7 +63,7 @@ public function removeReadStream($stream)

public function removeWriteStream($stream)
{
$id = (int) $stream;
$id = (int)$stream;

unset(
$this->writeStreams[$id],
Expand All @@ -79,15 +79,15 @@ public function removeStream($stream)

public function addTimer($interval, $callback)
{
$timer = new Timer($this, $interval, $callback, false);
$timer = new Timer($interval, $callback, false);
$this->timers->add($timer);

return $timer;
}

public function addPeriodicTimer($interval, $callback)
{
$timer = new Timer($this, $interval, $callback, true);
$timer = new Timer($interval, $callback, true);
$this->timers->add($timer);

return $timer;
Expand Down Expand Up @@ -146,18 +146,18 @@ protected function runStreamSelect()
if (socket_select($read, $write, $except, 0, $this->getNextEventTimeInMicroSeconds()) > 0) {
if ($read) {
foreach ($read as $stream) {
$listener = $this->readListeners[(int) $stream];
$listener = $this->readListeners[(int)$stream];
call_user_func($listener, $stream, $this);
}
}

if ($write) {
foreach ($write as $stream) {
if (!isset($this->writeListeners[(int) $stream])) {
if (!isset($this->writeListeners[(int)$stream])) {
continue;
}

$listener = $this->writeListeners[(int) $stream];
$listener = $this->writeListeners[(int)$stream];
call_user_func($listener, $stream, $this);
}
}
Expand Down Expand Up @@ -202,7 +202,34 @@ private function assertStream($stream)
}

if (!$checked[$type]) {
throw new InvalidArgumentException('Socket loop only accepts resources of type "Socket", but "' . $type .'" given');
throw new InvalidArgumentException('Socket loop only accepts resources of type "Socket", but "' . $type . '" given');
}
}

/**
* @inheritDoc
*/
public function futureTick($listener)
{
throw new \Exception('Not implemented yet');
}

/**
* @inheritDoc
*/
public function addSignal($signal, $listener)
{
throw new \Exception('Not implemented yet');

}

/**
* @inheritDoc
*/
public function removeSignal($signal, $listener)
{
throw new \Exception('Not implemented yet');
}


}