Skip to content

Commit

Permalink
Use fread() for STDIO instead of stream_get_contents()
Browse files Browse the repository at this point in the history
Turns out this fixes the issues with amphp/parallel on Windows.
  • Loading branch information
kelunik committed Dec 5, 2017
1 parent a1bd230 commit 3c24903
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ResourceInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct($stream, int $chunkSize = self::DEFAULT_CHUNK_SIZE)
}

$meta = \stream_get_meta_data($stream);
$isUdp = $meta["stream_type"] === "udp_socket";
$useFread = $meta["stream_type"] === "udp_socket" || $meta["stream_type"] === "STDIO";

if (\strpos($meta["mode"], "r") === false && \strpos($meta["mode"], "+") === false) {
throw new \Error("Expected a readable stream");
Expand All @@ -49,8 +49,8 @@ public function __construct($stream, int $chunkSize = self::DEFAULT_CHUNK_SIZE)
$deferred = &$this->deferred;
$readable = &$this->readable;

$this->watcher = Loop::onReadable($this->resource, static function ($watcher, $stream) use (&$deferred, &$readable, $chunkSize, $isUdp) {
if ($isUdp) {
$this->watcher = Loop::onReadable($this->resource, static function ($watcher, $stream) use (&$deferred, &$readable, $chunkSize, $useFread) {
if ($useFread) {
$data = @\fread($stream, $chunkSize);
} else {
$data = @\stream_get_contents($stream, $chunkSize);
Expand Down

0 comments on commit 3c24903

Please sign in to comment.