[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] cvs: pecl /http http_request_pool_api.c http_requestpool_object.c php_http_request_pool_a
From:       "Michael Wallner" <mike () php ! net>
Date:       2007-04-29 17:36:02
Message-ID: cvsmike1177868162 () cvsserver
[Download RAW message or body]

mike		Sun Apr 29 17:36:02 2007 UTC

  Modified files:              
    /pecl/http	http_request_pool_api.c http_requestpool_object.c 
              	php_http_request_pool_api.h 
              	php_http_requestpool_object.h 
  Log:
  - make libevent usable by choice at runtime
  
  
["mike-20070429173602.txt" (text/plain)]

http://cvs.php.net/viewvc.cgi/pecl/http/http_request_pool_api.c?r1=1.54&r2=1.55&diff_format=u
                
Index: pecl/http/http_request_pool_api.c
diff -u pecl/http/http_request_pool_api.c:1.54 pecl/http/http_request_pool_api.c:1.55
--- pecl/http/http_request_pool_api.c:1.54	Fri Apr 27 11:08:15 2007
+++ pecl/http/http_request_pool_api.c	Sun Apr 29 17:36:01 2007
@@ -10,7 +10,7 @@
     +--------------------------------------------------------------------+
 */
 
-/* $Id: http_request_pool_api.c,v 1.54 2007/04/27 11:08:15 mike Exp $ */
+/* $Id: http_request_pool_api.c,v 1.55 2007/04/29 17:36:01 mike Exp $ */
 
 #define HTTP_WANT_CURL
 #define HTTP_WANT_EVENT
@@ -120,8 +120,19 @@
 		http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not initialize HttpRequest \
object(#%d) for attaching to the HttpRequestPool", Z_OBJ_HANDLE_P(request));  } else \
{  CURLMcode code = curl_multi_add_handle(pool->ch, req->request->ch);
-
-		if ((CURLM_OK != code) && (CURLM_CALL_MULTI_PERFORM != code)) {
+		
+		while (CURLM_CALL_MULTI_PERFORM == code) {
+#ifdef HTTP_HAVE_EVENT
+			if (pool->useevents) {
+				code = curl_multi_socket_all(pool->ch, &pool->unfinished);
+			} else {
+#endif
+				code = curl_multi_perform(pool->ch, &pool->unfinished);
+#ifdef HTTP_HAVE_EVENT
+			}
+#endif
+		}
+		if (CURLM_OK != code) {
 			http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not attach HttpRequest \
object(#%d) to the HttpRequestPool: %s", Z_OBJ_HANDLE_P(request), \
curl_multi_strerror(code));  } else {
 			req->pool = pool;
@@ -256,23 +267,26 @@
 #endif
 	
 #ifdef HTTP_HAVE_EVENT
-	while (CURLM_CALL_MULTI_PERFORM == curl_multi_socket_all(pool->ch, \
                &pool->unfinished));
-	http_request_pool_update_timeout(pool);
-	
-	event_base_dispatch(HTTP_G->request.pool.event.base);
+	if (pool->useevents) {
+		while (CURLM_CALL_MULTI_PERFORM == curl_multi_socket_all(pool->ch, \
&pool->unfinished)); +		http_request_pool_update_timeout(pool);
+		
+		event_base_dispatch(HTTP_G->request.pool.event.base);
+	} else
+#endif
+	{
+		while (http_request_pool_perform(pool)) {
+			if (SUCCESS != http_request_pool_select(pool)) {
+#ifdef PHP_WIN32
+				/* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp \
*/ +				http_error_ex(HE_WARNING, HTTP_E_SOCKET, "WinSock error: %d", \
WSAGetLastError());  #else
-	while (http_request_pool_perform(pool)) {
-		if (SUCCESS != http_request_pool_select(pool)) {
-#	ifdef PHP_WIN32
-			/* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp \
                */
-			http_error_ex(HE_WARNING, HTTP_E_SOCKET, "WinSock error: %d", WSAGetLastError());
-#	else
-			http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno));
-#	endif
-			return FAILURE;
+				http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno));
+#endif
+				return FAILURE;
+			}
 		}
 	}
-#endif
 	
 #if HTTP_DEBUG_REQPOOLS
 	fprintf(stderr, "Finished sending %d HttpRequests of pool %p (still unfinished: \
%d)\n", zend_llist_count(&pool->handles), pool, pool->unfinished); @@ -311,15 +325,18 \
@@  /* {{{ STATUS http_request_pool_select(http_request_pool *) */
 PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool)
 {
-#ifdef HTTP_HAVE_EVENT
-	TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
-	http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use \
                HttpRequest::onProgress callback");
-	return FAILURE;
-#else
 	int MAX;
 	fd_set R, W, E;
 	struct timeval timeout;
 
+#ifdef HTTP_HAVE_EVENT
+	if (pool->useevents) {
+		TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
+		http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use HttpRequest \
callbacks"); +		return FAILURE;
+	}
+#endif
+	
 	http_request_pool_timeout(pool, &timeout);
 	
 	FD_ZERO(&R);
@@ -335,7 +352,6 @@
 		}
 	}
 	return FAILURE;
-#endif
 }
 /* }}} */
 
@@ -343,19 +359,23 @@
 PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool)
 {
 	TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
+	
 #ifdef HTTP_HAVE_EVENT
-	http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use \
                HttpRequest::onProgress callback");
-	return FAILURE;
-#else
-	CURLMsg *msg;
-	int remaining = 0;
+	if (pool->useevents) {
+		http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use HttpRequest \
callbacks"); +		return FAILURE;
+	}
+#endif
 	
 	while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(pool->ch, \
&pool->unfinished));  
-	http_request_pool_response_handler(pool);
+#if HTTP_DEBUG_REQPOOLS
+	fprintf(stderr, "%u unfinished requests of pool %p remaining\n", pool->unfinished, \
pool); +#endif
+	
+	http_request_pool_responsehandler(pool);
 	
 	return pool->unfinished;
-#endif
 }
 /* }}} */
 
@@ -519,15 +539,16 @@
 #endif
 	} while (CURLM_CALL_MULTI_PERFORM == rc);
 	
+#if HTTP_DEBUG_REQPOOLS
+	fprintf(stderr, "%u unfinished requests of pool %p remaining\n", pool->unfinished, \
pool); +#endif
+	
 	if (CURLM_OK != rc) {
 		http_error(HE_WARNING, HTTP_E_SOCKET, curl_multi_strerror(rc));
 	}
 	
 	http_request_pool_responsehandler(pool);
-	
-	if (!pool->unfinished) {
-		http_request_pool_update_timeout(pool);
-	}
+	http_request_pool_update_timeout(pool);
 }
 /* }}} */
 
@@ -543,14 +564,18 @@
 		ev = ecalloc(1, sizeof(http_request_pool_event));
 		ev->pool = pool;
 		curl_multi_assign(pool->ch, sock, ev);
+		fprintf(stderr, "+%2d\n", sock);
 	} else {
 		event_del(&ev->evnt);
+		fprintf(stderr, "-%2d\n", sock);
 	}
 	
 #if HTTP_DEBUG_REQPOOLS
 	{
 		static const char action_strings[][8] = {"NONE", "IN", "OUT", "INOUT", "REMOVE"};
-		fprintf(stderr, "Callback on socket %d (%s) event %p of pool %p\n", (int) sock, \
action_strings[action], ev, pool); +		http_request *r;
+		curl_easy_getinfo(easy, CURLINFO_PRIVATE, &r);
+		fprintf(stderr, "Callback on socket %d (%s) event %p of pool %p (%s)\n", (int) \
sock, action_strings[action], ev, pool, r->url);  }
 #endif
 	
http://cvs.php.net/viewvc.cgi/pecl/http/http_requestpool_object.c?r1=1.49&r2=1.50&diff_format=u
                
Index: pecl/http/http_requestpool_object.c
diff -u pecl/http/http_requestpool_object.c:1.49 \
                pecl/http/http_requestpool_object.c:1.50
--- pecl/http/http_requestpool_object.c:1.49	Wed Feb  7 11:50:27 2007
+++ pecl/http/http_requestpool_object.c	Sun Apr 29 17:36:01 2007
@@ -10,7 +10,7 @@
     +--------------------------------------------------------------------+
 */
 
-/* $Id: http_requestpool_object.c,v 1.49 2007/02/07 11:50:27 mike Exp $ */
+/* $Id: http_requestpool_object.c,v 1.50 2007/04/29 17:36:01 mike Exp $ */
 
 #define HTTP_WANT_CURL
 #include "php_http.h"
@@ -67,6 +67,10 @@
 	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 +97,7 @@
 	HTTP_REQPOOL_ME(getFinishedRequests, ZEND_ACC_PUBLIC)
 	
 	HTTP_REQPOOL_ME(enablePipelining, ZEND_ACC_PUBLIC)
+	HTTP_REQPOOL_ME(enableEvents, ZEND_ACC_PUBLIC)
 
 	EMPTY_FUNCTION_ENTRY
 };
@@ -397,7 +402,7 @@
 }
 /* }}} */
 
-/* {{{ 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)
 {
@@ -416,6 +421,23 @@
 }
 /* }}} */
 
+/* {{{ 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;
+	getObject(http_requestpool_object, obj);
+	
+	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 */
 
 /*
http://cvs.php.net/viewvc.cgi/pecl/http/php_http_request_pool_api.h?r1=1.21&r2=1.22&diff_format=u
                
Index: pecl/http/php_http_request_pool_api.h
diff -u pecl/http/php_http_request_pool_api.h:1.21 \
                pecl/http/php_http_request_pool_api.h:1.22
--- pecl/http/php_http_request_pool_api.h:1.21	Fri Apr 27 10:53:29 2007
+++ pecl/http/php_http_request_pool_api.h	Sun Apr 29 17:36:01 2007
@@ -10,7 +10,7 @@
     +--------------------------------------------------------------------+
 */
 
-/* $Id: php_http_request_pool_api.h,v 1.21 2007/04/27 10:53:29 mike Exp $ */
+/* $Id: php_http_request_pool_api.h,v 1.22 2007/04/29 17:36:01 mike Exp $ */
 
 #ifndef PHP_HTTP_REQUEST_POOL_API_H
 #define PHP_HTTP_REQUEST_POOL_API_H
@@ -27,6 +27,7 @@
 #endif
 #ifdef HTTP_HAVE_EVENT
 	struct event *timeout;
+	unsigned useevents:1;
 #endif
 } http_request_pool;
 
@@ -42,7 +43,7 @@
 extern struct timeval *_http_request_pool_timeout(http_request_pool *pool, struct \
timeval *timeout);  
 #define http_request_pool_responsehandler _http_request_pool_responsehandler
-extern void _http_request_pool_response_handler(http_request_pool *pool);
+extern void _http_request_pool_responsehandler(http_request_pool *pool);
 
 #define http_request_pool_apply_responsehandler _http_request_pool_responsehandler
 extern int _http_request_pool_apply_responsehandler(http_request_pool *pool, zval \
*req, void *ch); http://cvs.php.net/viewvc.cgi/pecl/http/php_http_requestpool_object.h?r1=1.17&r2=1.18&diff_format=u
                
Index: pecl/http/php_http_requestpool_object.h
diff -u pecl/http/php_http_requestpool_object.h:1.17 \
                pecl/http/php_http_requestpool_object.h:1.18
--- pecl/http/php_http_requestpool_object.h:1.17	Wed Feb  7 11:50:27 2007
+++ pecl/http/php_http_requestpool_object.h	Sun Apr 29 17:36:02 2007
@@ -10,7 +10,7 @@
     +--------------------------------------------------------------------+
 */
 
-/* $Id: php_http_requestpool_object.h,v 1.17 2007/02/07 11:50:27 mike Exp $ */
+/* $Id: php_http_requestpool_object.h,v 1.18 2007/04/29 17:36:02 mike Exp $ */
 
 #ifndef PHP_HTTP_REQUESTPOOL_OBJECT_H
 #define PHP_HTTP_REQUESTPOOL_OBJECT_H
@@ -52,6 +52,7 @@
 PHP_METHOD(HttpRequestPool, getAttachedRequests);
 PHP_METHOD(HttpRequestPool, getFinishedRequests);
 PHP_METHOD(HttpRequestPool, enablePipelining);
+PHP_METHOD(HttpRequestPool, enableEvents);
 
 #endif
 #endif



-- 
PECL CVS Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic