prepare v4.2.5
[m6w6/ext-http] / src / php_http_client_curl_user.c
index a30d666098489d81559aece92aee42247163fd38..2e646f60c7f5bc7f3ac845fbbaf0ea9f87bea7ec 100644 (file)
 #include "php_network.h"
 #include "zend_closures.h"
 
-#if PHP_HTTP_HAVE_CURL
+#if PHP_HTTP_HAVE_LIBCURL
 
 typedef struct php_http_client_curl_user_ev {
        php_stream *socket;
        php_http_client_curl_user_context_t *context;
 } php_http_client_curl_user_ev_t;
 
-static void php_http_client_curl_user_handler(INTERNAL_FUNCTION_PARAMETERS)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_user_handler, 0, 1, IS_LONG, 1)
+       ZEND_ARG_OBJ_INFO(0, client, "http\\Client", 0)
+       ZEND_ARG_TYPE_INFO(0, stream, IS_RESOURCE, 1)
+       ZEND_ARG_TYPE_INFO(0, action, IS_LONG, 1)
+ZEND_END_ARG_INFO();
+static ZEND_NAMED_FUNCTION(php_http_client_curl_user_handler)
 {
        zval *zstream = NULL, *zclient = NULL;
        php_stream *stream = NULL;
        long action = 0;
        php_socket_t fd = CURL_SOCKET_TIMEOUT;
        php_http_client_object_t *client = NULL;
+       php_http_client_curl_t *curl;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "O|rl", &zclient, php_http_client_get_class_entry(), &zstream, &action)) {
                return;
@@ -43,6 +49,9 @@ static void php_http_client_curl_user_handler(INTERNAL_FUNCTION_PARAMETERS)
                }
        }
        php_http_client_curl_loop(client->client, fd, action);
+
+       curl = client->client->ctx;
+       RETVAL_LONG(curl->unfinished);
 }
 
 static void php_http_client_curl_user_timer(CURLM *multi, long timeout_ms, void *timer_data)
@@ -53,9 +62,7 @@ static void php_http_client_curl_user_timer(CURLM *multi, long timeout_ms, void
        fprintf(stderr, "\ntimer <- timeout_ms: %ld\n", timeout_ms);
 #endif
 
-       if (timeout_ms <= 0) {
-               php_http_client_curl_loop(context->client, CURL_SOCKET_TIMEOUT, 0);
-       } else if (timeout_ms > 0) {
+       if (timeout_ms >= 0) {
                zval args[1], *ztimeout = &args[0];
 
                ZVAL_LONG(ztimeout, timeout_ms);
@@ -102,7 +109,7 @@ static int php_http_client_curl_user_socket(CURL *easy, curl_socket_t sock, int
                        return -1;
        }
 
-       if (action == CURL_POLL_REMOVE && ev) {
+       if (action == CURL_POLL_REMOVE) {
                php_stream_close(ev->socket);
                efree(ev);
                curl_multi_assign(curl->handle->multi, sock, NULL);
@@ -184,6 +191,10 @@ static void *php_http_client_curl_user_init(php_http_client_t *client, void *use
        ctx->closure.common.type = ZEND_INTERNAL_FUNCTION;
        ctx->closure.common.function_name = zend_string_init(ZEND_STRL("php_http_client_curl_user_handler"), 0);
        ctx->closure.internal_function.handler = php_http_client_curl_user_handler;
+       ctx->closure.internal_function.arg_info = (zend_internal_arg_info *) &ai_user_handler[1];
+       ctx->closure.internal_function.num_args = 3;
+       ctx->closure.internal_function.required_num_args = 1;
+
 
        zend_create_closure(zclosure, &ctx->closure, NULL, NULL, NULL);
 
@@ -256,7 +267,8 @@ zend_class_entry *php_http_client_curl_user_get_class_entry()
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_init, 0, 0, 1)
-       ZEND_ARG_TYPE_INFO(0, run, IS_CALLABLE, 0)
+       /* using IS_CALLABLE type hint would create a forwards compatibility break */
+       ZEND_ARG_INFO(0, run)
 ZEND_END_ARG_INFO();
 ZEND_BEGIN_ARG_INFO_EX(ai_timer, 0, 0, 1)
 #if PHP_VERSION_ID >= 70000
@@ -311,7 +323,7 @@ PHP_MINIT_FUNCTION(http_client_curl_user)
        return SUCCESS;
 }
 
-#endif /* PHP_HTTP_HAVE_CURL */
+#endif /* PHP_HTTP_HAVE_LIBCURL */
 
 /*
  * Local variables: