pollita Wed Jul 2 18:18:59 2003 EDT Modified files: /php-src/main/streams php_stream_context.h streams.c Log: Introduce connection pooling API. I'll use these in http/ftp fopen wrappers soon. Index: php-src/main/streams/php_stream_context.h diff -u php-src/main/streams/php_stream_context.h:1.6 php-src/main/streams/php_stream_context.h:1.7 --- php-src/main/streams/php_stream_context.h:1.6 Fri Jun 27 12:23:58 2003 +++ php-src/main/streams/php_stream_context.h Wed Jul 2 18:18:59 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_context.h,v 1.6 2003/06/27 16:23:58 pollita Exp $ */ +/* $Id: php_stream_context.h,v 1.7 2003/07/02 22:18:59 pollita Exp $ */ /* Stream context and status notification related definitions */ @@ -53,6 +53,7 @@ struct _php_stream_context { php_stream_notifier *notifier; zval *options; /* hash keyed by wrapper family or specific wrapper */ + zval *links; /* hash keyed by hostent for connection pooling */ int rsrc_id; /* used for auto-cleanup */ }; @@ -62,6 +63,13 @@ const char *wrappername, const char *optionname, zval ***optionvalue); PHPAPI int php_stream_context_set_option(php_stream_context *context, const char *wrappername, const char *optionname, zval *optionvalue); + +PHPAPI int php_stream_context_get_link(php_stream_context *context, + const char *hostent, php_stream **stream); +PHPAPI int php_stream_context_set_link(php_stream_context *context, + const char *hostent, php_stream *stream); +PHPAPI int php_stream_context_del_link(php_stream_context *context, + php_stream *stream); PHPAPI php_stream_notifier *php_stream_notification_alloc(void); PHPAPI void php_stream_notification_free(php_stream_notifier *notifier); Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.29 php-src/main/streams/streams.c:1.30 --- php-src/main/streams/streams.c:1.29 Fri Jun 27 12:23:58 2003 +++ php-src/main/streams/streams.c Wed Jul 2 18:18:59 2003 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.29 2003/06/27 16:23:58 pollita Exp $ */ +/* $Id: streams.c,v 1.30 2003/07/02 22:18:59 pollita Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -306,6 +306,11 @@ zend_list_delete(stream->rsrc_id); } + /* Remove stream from any context link list */ + if (stream->context && stream->context->links) { + php_stream_context_del_link(stream->context, stream); + } + if (close_options & PHP_STREAM_FREE_CALL_DTOR) { if (release_cast && stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) { /* calling fclose on an fopencookied stream will ultimately @@ -1626,6 +1631,10 @@ php_stream_notification_free(context->notifier); context->notifier = NULL; } + if (context->links) { + zval_ptr_dtor(&context->links); + context->links = NULL; + } efree(context); } @@ -1687,6 +1696,66 @@ wrapperhash = &category; } return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL); +} + +PHPAPI int php_stream_context_get_link(php_stream_context *context, + const char *hostent, php_stream **stream) +{ + php_stream **pstream; + + if (!stream || !hostent || !context || !(context->links)) { + return FAILURE; + } + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1, (void**)&pstream)) { + *stream = *pstream; + return SUCCESS; + } + return FAILURE; +} + +PHPAPI int php_stream_context_set_link(php_stream_context *context, + const char *hostent, php_stream *stream) +{ + if (!context) { + return FAILURE; + } + if (!context->links) { + ALLOC_INIT_ZVAL(context->links); + array_init(context->links); + } + if (!stream) { + /* Delete any entry for <hostent> */ + return zend_hash_del(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1); + } + return zend_hash_update(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1, (void**)&stream, sizeof(php_stream *), NULL); +} + +PHPAPI int php_stream_context_del_link(php_stream_context *context, + php_stream *stream) +{ + php_stream **pstream; + char *hostent; + int ret = SUCCESS; + + if (!context || !context->links || !stream) { + return FAILURE; + } + + for(zend_hash_internal_pointer_reset(Z_ARRVAL_P(context->links)); + SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(context->links), (void**)&pstream); + zend_hash_move_forward(Z_ARRVAL_P(context->links))) { + if (*pstream == stream) { + if (SUCCESS == zend_hash_get_current_key(Z_ARRVAL_P(context->links), &hostent, NULL, 0)) { + if (FAILURE == zend_hash_del(Z_ARRVAL_P(context->links), (char*)hostent, strlen(hostent)+1)) { + ret = FAILURE; + } + } else { + ret = FAILURE; + } + } + } + + return ret; } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php