diff options
author | Andreas Gohr <andi@splitbrain.org> | 2013-01-25 11:09:54 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2013-01-25 11:09:54 +0100 |
commit | 33e75ca2f63b10ae1c7c7e9891ae857ce80d1811 (patch) | |
tree | 481e679c75e8eb5a58bd3f71a48f26ec87d86db4 /inc/HTTPClient.php | |
parent | 3295f40a380553bb3f7f3018cee2e4462e0be417 (diff) | |
parent | a24fc53e2623640cf5e2d00de741c1b67c9bb294 (diff) | |
download | rpg-33e75ca2f63b10ae1c7c7e9891ae857ce80d1811.tar.gz rpg-33e75ca2f63b10ae1c7c7e9891ae857ce80d1811.tar.bz2 |
Merge branch 'confmanager' into future
* confmanager:
added failing test for array type
started to add some unit tests to config manager
Revert "config manager: let PHP parse the config file"
added 'array' type for config manager
config manager: let PHP parse the config file
config manager: removed dead/commented code
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
added event PAGEUTILS_ID_HIDEPAGE
added test for isHiddenPage()
add index file similar to fileicons to show active smileys
fix E_STRICT errors FS#2427
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 a25846c31..c4cfcbf7c 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -509,15 +509,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; } } @@ -556,15 +558,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; @@ -595,11 +599,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; } @@ -630,14 +636,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. |