Эх сурвалжийг харах

Share more code between connection classes.

Daniele Alessandri 14 жил өмнө
parent
commit
9954bd5a12

+ 2 - 13
lib/Predis/Network/ComposableStreamConnection.php

@@ -32,19 +32,8 @@ class ComposableStreamConnection extends StreamConnection implements IConnection
         return $this->_protocol;
     }
 
-    public function writeBytes($value) {
-        $socket = $this->getResource();
-        while (($length = strlen($value)) > 0) {
-            $written = fwrite($socket, $value);
-            if ($length === $written) {
-                return true;
-            }
-            if ($written === false || $written === 0) {
-                $this->onCommunicationException('Error while writing bytes to the server');
-            }
-            $value = substr($value, $written);
-        }
-        return true;
+    public function writeBytes($buffer) {
+        parent::writeBytes($buffer);
     }
 
     public function readBytes($length) {

+ 2 - 2
lib/Predis/Network/StreamConnection.php

@@ -94,7 +94,7 @@ class StreamConnection extends ConnectionBase {
         }
     }
 
-    private function write($buffer) {
+    protected function writeBytes($buffer) {
         $socket = $this->getResource();
         while (($length = strlen($buffer)) > 0) {
             $written = fwrite($socket, $buffer);
@@ -192,6 +192,6 @@ class StreamConnection extends ConnectionBase {
             $arglen  = strlen($argument);
             $buffer .= "\${$arglen}\r\n{$argument}\r\n";
         }
-        $this->write($buffer);
+        $this->writeBytes($buffer);
     }
 }