Code

Updated function output
[gosa.git] / gosa-core / include / class_socketClient.inc
index 653fc12d6a1f0936ba6fd0ec482a74da3145f209..c082f4748821896eae03e8232dd6ddc278d7d326 100644 (file)
@@ -107,32 +107,46 @@ class Socket_Client
                return $this->b_data_send;
        }
 
+       
+       private function _is_timeout($start,$stop = 0)
+       {
+               if($stop == 0){
+                       $stop = microtime();
+               }
+               $a = split("\ ",$start);
+               $b = split("\ ",$stop);
+               $secs = $b[1] - $a[1];
+               $msecs= $b[0] - $a[0];
+               $ret = (float) ($secs+ $msecs);
+               return($ret >= $this->timeout);
+       }
+
 
        public function read()
        {
-               $str = FALSE;
-               if($this->handle){
-
-                       syslog(0,"----------------------------------------HIER----------------------------------");
-       
-                       /* Check if there is something to read for us */
-                       $read = array("0"=>$this->handle);
-                       $write = array();
-                       $accept = array();      
-                       $num = @stream_select($read,$write,$accept,floor($this->timeout), ceil($this->timeout*1000000));
-                       $str = "";              
-               
-                       /* Read data if necessary */
-                       while($num && $this->b_data_send){
-                               $str.= fread($this->handle, 1024000);
-                               $read = array("0"=>$this->handle);      
-                               $num = @stream_select($read,$write,$accept,floor($this->timeout), ceil($this->timeout*1000000));
+               // Output the request results
+               $str = "";
+               $data = "test";
+               socket_set_timeout($this->handle,$this->timeout);                       
+               stream_set_blocking($this->handle,0);
+               $start = microtime();
+
+               while(strlen($str) == 0 || !$this->_is_timeout($start)) {
+                       usleep(10000);
+                       $data = fread($this->handle, 1024000);
+                       if($data && strlen($data)>0) {
+                               $str .= $data;
+                       } else {
+                               break;
                        }
-                       $this->bytes_read = strlen($str);
-                       $this->b_data_send = FALSE;
-                       $str = $this->decrypt($str);
                }
-               return $str;
+               if($this->_is_timeout($start)){
+                       trigger_error(sprintf("Exceeded timeout %f while reading from socket",$this->timeout));
+               }
+               $this->bytes_read = strlen($str);
+               $this->b_data_send = FALSE;
+               $str = $this->decrypt($str);
+               return($str);   
        }
 
 
@@ -149,7 +163,7 @@ class Socket_Client
                }
 
                /* Terminate decryption handle and close module */
-               mcrypt_generic_deinit($this->td);
+               @mcrypt_generic_deinit($this->td);
        }
 }
 ?>