index 6857112114b45fc0b6a1517c169ed72ac4049554..c082f4748821896eae03e8232dd6ddc278d7d326 100644 (file)
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()
{
// Output the request results
- $str = FALSE;
+ $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
- */
+ stream_set_blocking($this->handle,0);
$start = microtime();
- while(!preg_match("/\\\n$/",$str) && get_MicroTimeDiff($start,microtime()) < $this->timeout) {
+
+ while(strlen($str) == 0 || !$this->_is_timeout($start)) {
usleep(10000);
$data = fread($this->handle, 1024000);
- $str .= $data;
+ if($data && strlen($data)>0) {
+ $str .= $data;
+ } else {
+ break;
+ }
}
- 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())));
+ 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);
-
-
-# $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;
}