diff options
author | Andreas Gohr <andi@splitbrain.org> | 2012-11-08 23:15:08 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2012-11-08 23:15:08 +0100 |
commit | 04924b7a9d090c0814cfff3e6706263e4d5a46e8 (patch) | |
tree | d83fc6b5683fbc9c639bfd1832f96dca2f3c8646 /inc/HTTPClient.php | |
parent | 1ea7a6bada66fc9b7a45f61b4892e4ea23196d89 (diff) | |
parent | a731ed1d6736ca405b3559adfd9500affcc59412 (diff) | |
download | rpg-04924b7a9d090c0814cfff3e6706263e4d5a46e8.tar.gz rpg-04924b7a9d090c0814cfff3e6706263e4d5a46e8.tar.bz2 |
Merge branch 'master' into proxyconnect
* master: (169 commits)
added PCRE UTF-8 checks to do=check FS#2636
avoid multiple paralell update checks
fix regression bug in HTTPClient FS#2621
changed PAGEUTILS_ID_HIDEPAGE to has BEFORE/AFTER
TarLib code cleanup
TarLib: fixed appending in non-dynamic mode
fixed third method of adding files in TarLib
fix lone zero block in TarLib created archives
fix use of constructor in TarLib
Slovak language update
Korean language update
Latvian language update
added event PAGEUTILS_ID_HIDEPAGE
added test for isHiddenPage()
removed redundant variables in tpl_include_page() (because of 3ff8773b)
added cut off points for mobile devices as parameters to style.ini
Corrected typo: ruke -> rule
Persian language update
Spanish language update
russian language update
...
Diffstat (limited to 'inc/HTTPClient.php')
-rw-r--r-- | inc/HTTPClient.php | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 8d2c10be1..51c1de875 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -565,15 +565,17 @@ class HTTPClient { if(feof($socket)) throw new HTTPClientException("Socket disconnected while writing $message"); - // wait for stream ready or timeout - self::selecttimeout($this->timeout - $time_used, $sec, $usec); - if(@stream_select($sel_r, $sel_w, $sel_e, $sec, $usec) !== false){ - // write to stream - $nbytes = fwrite($socket, substr($data,$written,4096)); - if($nbytes === false) - throw new HTTPClientException("Failed writing to socket while sending $message", -100); - $written += $nbytes; + // wait for stream ready or timeout (1sec) + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; } + + // write to stream + $nbytes = fwrite($socket, substr($data,$written,4096)); + if($nbytes === false) + throw new HTTPClientException("Failed writing to socket while sending $message", -100); + $written += $nbytes; } } @@ -612,15 +614,17 @@ class HTTPClient { } if ($to_read > 0) { - // wait for stream ready or timeout - self::selecttimeout($this->timeout - $time_used, $sec, $usec); - if(@stream_select($sel_r, $sel_w, $sel_e, $sec, $usec) !== false){ - $bytes = fread($socket, $to_read); - if($bytes === false) - throw new HTTPClientException("Failed reading from socket while reading $message", -100); - $r_data .= $bytes; - $to_read -= strlen($bytes); + // wait for stream ready or timeout (1sec) + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; } + + $bytes = fread($socket, $to_read); + if($bytes === false) + throw new HTTPClientException("Failed reading from socket while reading $message", -100); + $r_data .= $bytes; + $to_read -= strlen($bytes); } } while ($to_read > 0 && strlen($r_data) < $nbytes); return $r_data; @@ -651,11 +655,13 @@ class HTTPClient { if(feof($socket)) throw new HTTPClientException("Premature End of File (socket) while reading $message"); - // wait for stream ready or timeout - self::selecttimeout($this->timeout - $time_used, $sec, $usec); - if(@stream_select($sel_r, $sel_w, $sel_e, $sec, $usec) !== false){ - $r_data = fgets($socket, 1024); + // wait for stream ready or timeout (1sec) + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; } + + $r_data = fgets($socket, 1024); } while (!preg_match('/\n$/',$r_data)); return $r_data; } @@ -686,14 +692,6 @@ class HTTPClient { } /** - * Calculate seconds and microseconds - */ - static function selecttimeout($time, &$sec, &$usec){ - $sec = floor($time); - $usec = (int)(($time - $sec) * 1000000); - } - - /** * convert given header string to Header array * * All Keys are lowercased. |