Skip to content

Always wrap Stream if SSL #26

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

Merged
merged 1 commit into from
Mar 20, 2015
Merged
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
20 changes: 8 additions & 12 deletions src/StreamEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ class StreamEncryption

private $errstr;
private $errno;

private $wrapSecure = false;

public function __construct(LoopInterface $loop)
{
$this->loop = $loop;

// See https://bugs.php.net/bug.php?id=65137
// https://bugs.php.net/bug.php?id=41631
// https://github.com/reactphp/socket-client/issues/24
// On versions affected by this bug we need to fread the stream until we
// get an empty string back because the buffer indicator could be wrong
if (
PHP_VERSION_ID < 50433
|| (PHP_VERSION_ID >= 50500 && PHP_VERSION_ID < 50517)
|| PHP_VERSION_ID === 50600
) {
$this->wrapSecure = true;
}
$this->wrapSecure = true;
}

public function enable(Stream $stream)
Expand All @@ -50,7 +46,7 @@ public function disable(Stream $stream)
public function toggle(Stream $stream, $toggle)
{
if (__NAMESPACE__ . '\SecureStream' === get_class($stream)) {
$stream = $stream->decorating;
$stream = $stream->decorating;
}

// pause actual stream instance to continue operation on raw stream socket
Expand All @@ -74,9 +70,9 @@ public function toggle(Stream $stream, $toggle)
if ($toggle && $this->wrapSecure) {
return new SecureStream($stream, $this->loop);
}

$stream->resume();

return $stream;
}, function($error) use ($stream) {
$stream->resume();
Expand Down