branch off v1 as R_1_7
[m6w6/ext-http] / http_requestpool_object.c
index 3e81a6a4c7d3d8f5d06eda67ff56cdb62277ec79..a0f219cb8429094abeb9f6b97da1f92c1f63ecda 100644 (file)
@@ -6,7 +6,7 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2007, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2010, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
@@ -50,7 +50,9 @@ HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(send);
 HTTP_EMPTY_ARGS(socketPerform);
-HTTP_EMPTY_ARGS(socketSelect);
+HTTP_BEGIN_ARGS(socketSelect, 0)
+       HTTP_ARG_VAL(timeout, 0)
+HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(valid);
 HTTP_EMPTY_ARGS(current);
@@ -67,6 +69,10 @@ HTTP_BEGIN_ARGS(enablePipelining, 0)
        HTTP_ARG_VAL(enable, 0)
 HTTP_END_ARGS;
 
+HTTP_BEGIN_ARGS(enableEvents, 0)
+       HTTP_ARG_VAL(enable, 0)
+HTTP_END_ARGS;
+
 zend_class_entry *http_requestpool_object_ce;
 zend_function_entry http_requestpool_object_fe[] = {
        HTTP_REQPOOL_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
@@ -93,6 +99,7 @@ zend_function_entry http_requestpool_object_fe[] = {
        HTTP_REQPOOL_ME(getFinishedRequests, ZEND_ACC_PUBLIC)
        
        HTTP_REQPOOL_ME(enablePipelining, ZEND_ACC_PUBLIC)
+       HTTP_REQPOOL_ME(enableEvents, ZEND_ACC_PUBLIC)
 
        EMPTY_FUNCTION_ENTRY
 };
@@ -122,9 +129,14 @@ zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC)
 
        http_request_pool_init(&o->pool);
 
+#ifdef ZEND_ENGINE_2_4
+       zend_object_std_init(o, ce TSRMLS_CC);
+       object_properties_init(o, ce);
+#else
        ALLOC_HASHTABLE(OBJ_PROP(o));
        zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
        zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+#endif
 
        ov.handle = putObject(http_requestpool_object, o);
        ov.handlers = &http_requestpool_object_handlers;
@@ -168,8 +180,8 @@ PHP_METHOD(HttpRequestPool, __construct)
                }
        }
        efree(argv);
-       SET_EH_NORMAL();
        http_final(HTTP_EX_CE(request_pool));
+       SET_EH_NORMAL();
 }
 /* }}} */
 
@@ -272,14 +284,23 @@ PHP_METHOD(HttpRequestPool, socketPerform)
 }
 /* }}} */
 
-/* {{{ proto protected bool HttpRequestPool::socketSelect() */
+/* {{{ proto protected bool HttpRequestPool::socketSelect([double timeout]) */
 PHP_METHOD(HttpRequestPool, socketSelect)
 {
+       double timeout = 0;
+       struct timeval custom_timeout, *custom_timeout_ptr = NULL;
        getObject(http_requestpool_object, obj);
 
-       NO_ARGS;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout)) {
+               RETURN_FALSE;
+       }
+       if (ZEND_NUM_ARGS() && timeout > 0) {
+               custom_timeout.tv_sec = (time_t) timeout;
+               custom_timeout.tv_usec = HTTP_USEC(timeout) % HTTP_MCROSEC;
+               custom_timeout_ptr = &custom_timeout;
+       }
 
-       RETURN_SUCCESS(http_request_pool_select(&obj->pool));
+       RETURN_SUCCESS(http_request_pool_select_ex(&obj->pool, custom_timeout_ptr));
 }
 /* }}} */
 
@@ -397,12 +418,14 @@ PHP_METHOD(HttpRequestPool, getFinishedRequests)
 }
 /* }}} */
 
-/* {{{ proto bool HttpRequest::enablePiplelinig([bool enable = true])
+/* {{{ proto bool HttpRequestPool::enablePipelining([bool enable = true])
        Enables pipelining support for all attached requests if support in libcurl is given. */
 PHP_METHOD(HttpRequestPool, enablePipelining)
 {
        zend_bool enable = 1;
+#if defined(HAVE_CURL_MULTI_SETOPT) && HTTP_CURL_VERSION(7,16,0)
        getObject(http_requestpool_object, obj);
+#endif
        
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
                RETURN_FALSE;
@@ -416,6 +439,25 @@ PHP_METHOD(HttpRequestPool, enablePipelining)
 }
 /* }}} */
 
+/* {{{ proto bool HttpRequestPool::enableEvents([bool enable = true])
+       Enables event-driven I/O if support in libcurl is given. */
+PHP_METHOD(HttpRequestPool, enableEvents)
+{
+       zend_bool enable = 1;
+#if defined(HTTP_HAVE_EVENT)
+       getObject(http_requestpool_object, obj);
+#endif
+       
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
+#if defined(HTTP_HAVE_EVENT)
+               obj->pool.useevents = enable;
+               RETURN_TRUE;
+#endif
+       }
+       RETURN_FALSE;
+}
+/* }}} */
+
 #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
 
 /*