diff --git a/src/Engine/AbstractSocketIO.php b/src/Engine/AbstractSocketIO.php index 3a09b19..548df6c 100644 --- a/src/Engine/AbstractSocketIO.php +++ b/src/Engine/AbstractSocketIO.php @@ -21,6 +21,7 @@ use ElephantIO\Payload\Decoder; use ElephantIO\Exception\UnsupportedActionException; use ElephantIO\Exception\MalformedUrlException; +use ElephantIO\Exception\ServerConnectionFailureException; abstract class AbstractSocketIO implements EngineInterface { @@ -112,9 +113,15 @@ protected function readBytes($bytes) { $data = ''; $chunk = null; + $i = 0; while ($bytes > 0 && false !== ($chunk = \fread($this->stream, $bytes))) { + if ($i > 2) { + throw new ServerConnectionFailureException('fread times error'); + } + $bytes -= \strlen($chunk); $data .= $chunk; + $i++; } if (false === $chunk) { @@ -136,6 +143,7 @@ public function read() } $this->keepAlive(); + /* * The first byte contains the FIN bit, the reserved bits, and the * opcode... We're not interested in them. Yet. diff --git a/src/Engine/SocketIO/Version1X.php b/src/Engine/SocketIO/Version1X.php index ea2d7ef..3c48b45 100644 --- a/src/Engine/SocketIO/Version1X.php +++ b/src/Engine/SocketIO/Version1X.php @@ -126,6 +126,7 @@ public function write($code, $message = null) } $payload = new Encoder($code . $message, Encoder::OPCODE_TEXT, true); + $bytes = @\fwrite($this->stream, (string) $payload); if ($bytes === false){