Code

Updated Socket read mechanism.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 22 Jan 2008 07:34:40 +0000 (07:34 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 22 Jan 2008 07:34:40 +0000 (07:34 +0000)
- Read while last character is \n or we exceeded the timelimit.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8530 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_socketClient.inc

index 72230451b4fda08f689fe71c557afe26680fde03..008308e75a12ffe19e8872c3f1b63bbba1f3a01c 100644 (file)
@@ -110,29 +110,52 @@ class Socket_Client
 
        public function read()
        {
+               // Output the request results
                $str = FALSE;
-               if($this->handle){
-
-                       /* Check if there is something to read for us */
-                       $read = array("0"=>$this->handle);
-                       $write = array();
-                       $accept = array();      
-                       $start = microtime();           
-                       $num = @stream_select($read,$write,$accept,floor($this->timeout), ceil($this->timeout*100000));
-                       $str = "";              
-                       socket_set_timeout($this->handle,$this->timeout);                       
-
-                       /* Read data if necessary */
-                       while($num && get_MicroTimeDiff($start,microtime()) < $this->timeout){
-                               $str.= fread($this->handle, 1024000);
-                               $read = array("0"=>$this->handle);      
-                               $num = stream_select($read,$write,$accept,0,200);
-                       }
-                       $this->bytes_read = strlen($str);
-                       $this->b_data_send = FALSE;
-                       $str = $this->decrypt($str);
+               $data = "test";
+               socket_set_timeout($this->handle,$this->timeout);                       
+               stream_set_blocking($this->handle,1);
+
+               /* Read while last character is Newline, or we exceeded the timelimit 
+         */
+               $start = microtime();
+               while(!preg_match("/\\\n$/",$str) && get_MicroTimeDiff($start,microtime()) < $this->timeout) {
+                       usleep(10000);
+                       $data = fread($this->handle, 1024000);
+                       $str .= $data;
+               }
+               if(get_MicroTimeDiff($start,microtime()) >= $this->timeout){
+                       trigger_error(sprintf("Exceeded timeout %f while reading from socket. Time spend for reading was %f.",$this->timeout,get_MicroTimeDiff($start,microtime())));
                }
-               return $str;
+               $this->bytes_read = strlen($str);
+               $this->b_data_send = FALSE;
+               $str = $this->decrypt($str);
+               return($str);   
+
+
+#      $str = FALSE;
+#      if($this->handle){
+#
+#              /* Check if there is something to read for us */
+#              $read = array("0"=>$this->handle);
+#              $write = array();
+#              $accept = array();      
+#              $start = microtime();           
+#              $num = @stream_select($read,$write,$accept,floor($this->timeout), ceil($this->timeout*100000));
+#              $str = "";              
+#              socket_set_timeout($this->handle,$this->timeout);                       
+#
+#              /* Read data if necessary */
+#              while($num && get_MicroTimeDiff($start,microtime()) < $this->timeout){
+#                      $str.= fread($this->handle, 1024000);
+#                      $read = array("0"=>$this->handle);      
+#                      $num = stream_select($read,$write,$accept,0,200000);
+#              }
+#              $this->bytes_read = strlen($str);
+#              $this->b_data_send = FALSE;
+#              $str = $this->decrypt($str);
+#      }
+#      return $str;
        }