Skip to content

Commit

Permalink
replace native implementation of curl_multi_await with a systemlib one
Browse files Browse the repository at this point in the history
Summary:
- this actually performs better for most cases than spinning up another thread
 - we've never got the native implementation actually reliable

fixes #8043
fixes #7485

Reviewed By: jano

Differential Revision: D6602518

fbshipit-source-id: a9dce3e46dba474b4fce00604e8dee54c316fc1b
  • Loading branch information
fredemmott authored and hhvm-bot committed Jan 4, 2018
1 parent cd35baa commit 9273c7e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 211 deletions.
2 changes: 0 additions & 2 deletions hphp/runtime/ext/curl/config.cmake
@@ -1,13 +1,11 @@
HHVM_DEFINE_EXTENSION("curl"
SOURCES
curl-multi-await.cpp
curl-multi-resource.cpp
curl-pool.cpp
curl-resource.cpp
ext_curl.cpp
curl-share-resource.cpp
HEADERS
curl-multi-await.h
curl-multi-resource.h
curl-pool.h
curl-resource.h
Expand Down
152 changes: 0 additions & 152 deletions hphp/runtime/ext/curl/curl-multi-await.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions hphp/runtime/ext/curl/curl-multi-await.h

This file was deleted.

15 changes: 0 additions & 15 deletions hphp/runtime/ext/curl/ext_curl.cpp
Expand Up @@ -16,7 +16,6 @@
*/

#include "hphp/runtime/ext/curl/ext_curl.h"
#include "hphp/runtime/ext/curl/curl-multi-await.h"
#include "hphp/runtime/ext/curl/curl-multi-resource.h"
#include "hphp/runtime/ext/curl/curl-pool.h"
#include "hphp/runtime/ext/curl/curl-resource.h"
Expand Down Expand Up @@ -594,19 +593,6 @@ Variant HHVM_FUNCTION(curl_multi_select, const Resource& mh,
return ret;
}

Object HHVM_FUNCTION(curl_multi_await, const Resource& mh,
double timeout /*=1.0*/) {
CHECK_MULTI_RESOURCE_THROW(curlm);
auto ev = new CurlMultiAwait(curlm, timeout);
try {
return Object{ev->getWaitHandle()};
} catch (...) {
assert(false);
ev->abandon();
throw;
}
}

Variant HHVM_FUNCTION(curl_multi_getcontent, const Resource& ch) {
CHECK_RESOURCE(curl);
return curl->getContents();
Expand Down Expand Up @@ -1480,7 +1466,6 @@ struct CurlExtension final : Extension {
HHVM_FE(curl_multi_remove_handle);
HHVM_FE(curl_multi_exec);
HHVM_FE(curl_multi_select);
HHVM_FE(curl_multi_await);
HHVM_FE(curl_multi_getcontent);
HHVM_FE(curl_multi_setopt);
HHVM_FE(fb_curl_multi_fdset);
Expand Down
21 changes: 15 additions & 6 deletions hphp/runtime/ext/curl/ext_curl.php
Expand Up @@ -280,7 +280,7 @@ function curl_multi_select(resource $mh,
*
* @param $mh - A cURL multi handle returned from
* [`curl_multi_init`](http://php.net/manual/en/function.curl-multi-init.php).
* @param $timeout - The time to wait for a response indicating some activity.
* @param $timeout - The time (in seconds) to wait for a response indicating some activity.
*
* @return Awaitable<int> - An `Awaitable` representing the `int` result of the
* activity. If returned `int` is positive, that
Expand All @@ -291,12 +291,21 @@ function curl_multi_select(resource $mh,
*
* @guide /hack/async/introduction
* @guide /hack/async/extensions
*
* See curl_exec() wrt NoFCallBuiltin.
*/
<<__Native("NoFCallBuiltin")>>
function curl_multi_await(resource $mh,
float $timeout = 1.0): Awaitable<int>;
async function curl_multi_await(
resource $mh,
float $timeout = 1.0,
): Awaitable<int> {
$finish_by = \microtime(true) + $timeout;
do {
$result = \curl_multi_select($mh, 0.0);
if ($result !== 0) {
return $result;
}
await \HH\Asio\later();
} while (\microtime(true) < $finish_by);
return 0;
}

/**
* Wait for activity on any curl_multi connection
Expand Down

0 comments on commit 9273c7e

Please sign in to comment.