Skip to content

Commit

Permalink
Implement curl_multi_setopt function
Browse files Browse the repository at this point in the history
Summary: Fix for #5761
Closes #6558

Reviewed By: sgolemon, JoelMarcey

Differential Revision: D2662237

Pulled By: JoelMarcey

fb-gh-sync-id: 1f0e65e5c27cf8775ecc7037448234f9eabd6288
  • Loading branch information
Thomas Colomb authored and hhvm-bot committed Nov 29, 2015
1 parent 607d785 commit 8328b80
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
51 changes: 51 additions & 0 deletions hphp/runtime/ext/curl/ext_curl.cpp
Expand Up @@ -1456,6 +1456,41 @@ class CurlMultiResource : public SweepableResourceData {
}
}

bool setOption(int option, const Variant& value) {
#if LIBCURL_VERSION_NUM <= 0x070f04 /* 7.15.4 */
return false;
#endif
if (m_multi == nullptr) {
return false;
}

CURLMcode error = CURLM_OK;
switch (option) {
#if LIBCURL_VERSION_NUM >= 0x071000 /* 7.16.0 */
case CURLMOPT_PIPELINING:

#if LIBCURL_VERSION_NUM >= 0x071003 /* 7.16.3 */
case CURLMOPT_MAXCONNECTS:
#endif
error = curl_multi_setopt(m_multi,
(CURLMoption)option,
value.toInt64());
break;
#endif
default:
raise_warning("curl_multi_setopt():"
"Invalid curl multi configuration option");
error = CURLM_UNKNOWN_OPTION;
break;
}

if (error != CURLM_OK) {
return false;
} else {
return true;
}
}

bool isInvalid() const override {
return !m_multi;
}
Expand Down Expand Up @@ -1591,6 +1626,13 @@ Variant HHVM_FUNCTION(curl_multi_exec, const Resource& mh, VRefParam still_runni
return result;
}

bool HHVM_FUNCTION(curl_multi_setopt, const Resource& mh,
int option, const Variant& value) {
CHECK_MULTI_RESOURCE_THROW(curlm);
return curlm->setOption(option, value);
}


/* Fallback implementation of curl_multi_select()
*
* This allows the OSS build to work with older package
Expand Down Expand Up @@ -1894,6 +1936,14 @@ class CurlExtension final : public Extension {
HHVM_RC_INT_SAME(CURLOPT_CONNECTTIMEOUT_MS);
#endif

#if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
HHVM_RC_INT_SAME(CURLMOPT_PIPELINING);
#endif

#if LIBCURL_VERSION_NUM >= 0x071003 /* Available since 7.16.3 */
HHVM_RC_INT_SAME(CURLMOPT_MAXCONNECTS);
#endif

HHVM_RC_INT_SAME(CURLAUTH_ANY);
HHVM_RC_INT_SAME(CURLAUTH_ANYSAFE);
HHVM_RC_INT_SAME(CURLAUTH_BASIC);
Expand Down Expand Up @@ -2181,6 +2231,7 @@ class CurlExtension final : public Extension {
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);
HHVM_FE(curl_multi_info_read);
HHVM_FE(curl_multi_close);
Expand Down
3 changes: 3 additions & 0 deletions hphp/runtime/ext/curl/ext_curl.h
Expand Up @@ -56,6 +56,9 @@ Variant HHVM_FUNCTION(fb_curl_multi_fdset, const Resource& mh,
Variant HHVM_FUNCTION(curl_multi_info_read, const Resource& mh,
VRefParam msgs_in_queue = null_object);
Variant HHVM_FUNCTION(curl_multi_close, const Resource& mh);
bool HHVM_FUNCTION(curl_multi_setopt, const Resource& mh,
int option,
const Variant& value);

///////////////////////////////////////////////////////////////////////////////
}
Expand Down
12 changes: 12 additions & 0 deletions hphp/runtime/ext/curl/ext_curl.php
Expand Up @@ -263,6 +263,18 @@ function curl_multi_select(resource $mh,
function curl_multi_await(resource $mh,
float $timeout = 1.0): Awaitable<int>;

/**
* Wait for activity on any curl_multi connection
*
* @param resource $mh -
* @param int $option - One of the CURLMOPT_* constants.
* @param int $option - The value to be set on option.
*
* @return Returns TRUE on success or FALSE on failure.
*/
<<__Native>>
function curl_multi_setopt(resource $mh, int $option, mixed $value) : bool;

/**
* Set multiple options for a cURL transfer
*
Expand Down

0 comments on commit 8328b80

Please sign in to comment.