Change run() to serve() in all Thrift server interfaces


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664799 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/transport/TSocket.php b/lib/php/src/transport/TSocket.php
index 74ef01f..5ecd874 100644
--- a/lib/php/src/transport/TSocket.php
+++ b/lib/php/src/transport/TSocket.php
@@ -165,12 +165,28 @@
       stream_set_timeout($this->handle_, 0, $this->recvTimeout_*1000);
       $this->sendTimeoutSet_ = FALSE;
     }
-    $buf = @stream_get_contents($this->handle_, $len);
-    if ($buf === FALSE || strlen($buf) !== $len) {
-      throw new Exception('TSocket: Could not read '.$len.' bytes from '.
-                          $this->host_.':'.$this->port_);
+    // This call does not obey stream_set_timeout values!
+    // $buf = @stream_get_contents($this->handle_, $len);
+
+    $pre = null;
+    while (true) {
+      $buf = @fread($this->handle_, $len);
+      if ($buf === FALSE) {
+        throw new Exception('TSocket: Could not read '.$len.' bytes from '.
+                            $this->host_.':'.$this->port_);
+      } else if (($sz = strlen($buf)) < $len) {
+        $md = stream_get_meta_data($this->handle_);
+        if ($md['timed_out']) {
+          throw new Exception('TSocket: timed out reading '.$len.' bytes from '.
+                              $this->host_.':'.$this->port_);
+        } else {
+          $pre .= $buf;
+          $len -= $sz;
+        }
+      } else {
+        return $pre.$buf;
+      }
     }
-    return $buf;
   }
 
   /**
@@ -184,7 +200,7 @@
       stream_set_timeout($this->handle_, 0, $this->recvTimeout_*1000);
       $this->sendTimeoutSet_ = FALSE;
     }
-    $data = @fread($this->handle_, 1);
+    $data = @fread($this->handle_, $len);
     if ($data === FALSE) {
       throw new Exception('TSocket: Could not read '.$len.' bytes from '.
                           $this->host_.':'.$this->port_);