Skip to content

Commit

Permalink
Merge pull request #42 from Hywan/changelog
Browse files Browse the repository at this point in the history
mv ChangeLog.md CHANGELOG.md for consistency
  • Loading branch information
evert committed Feb 18, 2015
2 parents a75baa1 + cb32e96 commit b96b7df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
File renamed without changes.
26 changes: 18 additions & 8 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function send(RequestInterface $request) {

$response = $this->doRequest($request);

$code = (int)$response->getStatus();
$code = (int) $response->getStatus();

// We are doing in-PHP redirects, because curl's
// FOLLOW_LOCATION throws errors when PHP is configured with
Expand Down Expand Up @@ -133,6 +133,7 @@ function send(RequestInterface $request) {
}

} catch (ClientException $e) {

$this->emit('exception', [$request, $e, &$retry, $retryCount]);

// If retry was still set to false, it means no event handler
Expand All @@ -141,7 +142,9 @@ function send(RequestInterface $request) {
if (!$retry) {
throw $e;
}

}

if ($retry) {
$retryCount++;
}
Expand Down Expand Up @@ -212,6 +215,7 @@ function poll() {
$this->curlMultiHandle,
$messagesInQueue
);

if ($status && $status['msg'] === CURLMSG_DONE) {

$resourceId = intval($status['handle']);
Expand All @@ -221,23 +225,23 @@ function poll() {
$errorCallback,
$retryCount,
) = $this->curlMultiMap[$resourceId];

unset($this->curlMultiMap[$resourceId]);

$curlResult = $this->parseCurlResult(curl_multi_getcontent($status['handle']), $status['handle']);

$retry = false;

if ($curlResult['status'] === self::STATUS_CURLERROR) {

$e = new ClientException($curlResult['curl_errmsg'], $curlResult['curl_errno']);
$this->emit('exception', [$request, $e, &$retry, $retryCount]);

if ($retry) {
$retryCount++;
$this->sendASyncInternal($request, $successCallback, $errorCallback, $retryCount);
goto messageQueue;
}

$curlResult['request'] = $request;

if ($errorCallback) {
$errorCallback($curlResult);
}
Expand All @@ -248,21 +252,30 @@ function poll() {
$this->emit('error:' . $curlResult['http_code'], [$request, $curlResult['response'], &$retry, $retryCount]);

if ($retry) {

$retryCount++;
$this->sendASyncInternal($request, $successCallback, $errorCallback, $retryCount);
goto messageQueue;

}

$curlResult['request'] = $request;

if ($errorCallback) {
$errorCallback($curlResult);
}

} else {

$this->emit('afterRequest', [$request, $curlResult['response']]);

if ($successCallback) {
$successCallback($curlResult['response']);
}

}
}

} while ($messagesInQueue > 0);

return $stillRunning;
Expand Down Expand Up @@ -334,7 +347,6 @@ protected function doRequest(RequestInterface $request) {

curl_setopt_array($this->curlHandle, $settings);
$response = $this->curlExec($this->curlHandle);

$response = $this->parseCurlResult($response, $this->curlHandle);

if ($response['status'] === self::STATUS_CURLERROR) {
Expand Down Expand Up @@ -485,7 +497,6 @@ protected function parseCurlResult($response, $curlHandle) {
unset($response);

// In the case of 100 Continue, or redirects we'll have multiple lists
//
// of headers for each separate HTTP response. We can easily split this
// because they are separated by \r\n\r\n
$headerBlob = explode("\r\n\r\n", trim($headerBlob, "\r\n"));
Expand Down Expand Up @@ -519,7 +530,7 @@ protected function parseCurlResult($response, $curlHandle) {
}

/**
* Sends a asynchrous http request.
* Sends an asynchronous HTTP request.
*
* We keep this in a separate method, so we can call it without triggering
* the beforeRequest event and don't do the poll().
Expand Down Expand Up @@ -558,7 +569,6 @@ protected function sendAsyncInternal(RequestInterface $request, callable $succes
*
* @param resource $curlHandle
* @return string
*/
protected function curlExec($curlHandle) {

Expand Down

0 comments on commit b96b7df

Please sign in to comment.