summaryrefslogtreecommitdiff
path: root/ext/curl/multi.c
diff options
context:
space:
mode:
authorDavey Shafik <me@daveyshafik.com>2015-12-02 16:47:52 -0500
committerDavey Shafik <me@daveyshafik.com>2016-06-27 00:52:46 -0700
commitd56d2f452baa717d18a25e1a3a69ef5f6e0ffaa0 (patch)
treec9ec0da4a88c71e9f8e5e93769a70a558b3a7083 /ext/curl/multi.c
parent63275a1e58a827e4cbb0df4f1b76707adbf5c639 (diff)
downloadphp-git-d56d2f452baa717d18a25e1a3a69ef5f6e0ffaa0.tar.gz
Refactor easy handle lookup
Diffstat (limited to 'ext/curl/multi.c')
-rw-r--r--ext/curl/multi.c67
1 files changed, 38 insertions, 29 deletions
diff --git a/ext/curl/multi.c b/ext/curl/multi.c
index da99f8f140..7bc3ba7f05 100644
--- a/ext/curl/multi.c
+++ b/ext/curl/multi.c
@@ -135,6 +135,29 @@ static int curl_compare_resources( zval *z1, zval *z2 ) /* {{{ */
}
/* }}} */
+/* Used to find the php_curl resource for a given curl easy handle */
+static zval *_php_curl_multi_find_easy_handle(php_curlm *mh, CURL *easy) /* {{{ */
+{
+ php_curl *tmp_ch;
+ zend_llist_position pos;
+ zval *pz_ch_temp;
+
+ for(pz_ch_temp = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch_temp;
+ pz_ch_temp = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
+
+ if ((tmp_ch = (php_curl *)zend_fetch_resource(Z_RES_P(pz_ch_temp), le_curl_name, le_curl)) == NULL) {
+ return NULL;
+ }
+
+ if (tmp_ch->cp == easy) {
+ return pz_ch_temp;
+ }
+ }
+
+ return NULL;
+}
+/* }}} */
+
/* {{{ proto int curl_multi_remove_handle(resource mh, resource ch)
Remove a multi handle from a set of cURL handles */
PHP_FUNCTION(curl_multi_remove_handle)
@@ -318,35 +341,21 @@ PHP_FUNCTION(curl_multi_info_read)
/* find the original easy curl handle */
{
- zend_llist_position pos;
- php_curl *ch;
- zval *pz_ch;
-
- /* search the list of easy handles hanging off the multi-handle */
- for(pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
- pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
-
- if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(pz_ch), le_curl_name, le_curl)) == NULL) {
- RETURN_FALSE;
- }
- if (ch->cp == tmp_msg->easy_handle) {
-
- /* we are adding a reference to the underlying php_curl
- resource, so we need to add one to the resource's refcount
- in order to ensure it doesn't get destroyed when the
- underlying curl easy handle goes out of scope.
- Normally you would call zval_copy_ctor( pz_ch ), or
- SEPARATE_ZVAL, but those create new zvals, which is already
- being done in add_assoc_resource */
- Z_ADDREF_P(pz_ch);
-
- /* add_assoc_resource automatically creates a new zval to
- wrap the "resource" represented by the current pz_ch */
-
- add_assoc_zval(return_value, "handle", pz_ch);
-
- break;
- }
+ zval *pz_ch = _php_curl_multi_find_easy_handle(mh, tmp_msg->easy_handle);
+ if (pz_ch != NULL) {
+ /* we are adding a reference to the underlying php_curl
+ resource, so we need to add one to the resource's refcount
+ in order to ensure it doesn't get destroyed when the
+ underlying curl easy handle goes out of scope.
+ Normally you would call zval_copy_ctor( pz_ch ), or
+ SEPARATE_ZVAL, but those create new zvals, which is already
+ being done in add_assoc_resource */
+ Z_ADDREF_P(pz_ch);
+
+ /* add_assoc_resource automatically creates a new zval to
+ wrap the "resource" represented by the current pz_ch */
+
+ add_assoc_zval(return_value, "handle", pz_ch);
}
}
}