cvs: php4 /main main.c network.c php_streams.h streams.c

From: Date: Tue, 30 Apr 2002 00:16:02 +0000
Subject: cvs: php4 /main main.c network.c php_streams.h streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11542@lists.php.net to get a copy of this message
wez Mon Apr 29 20:16:02 2002 EDT Modified files: /php4/main main.c network.c php_streams.h streams.c Log: Implement context option setting API. Add/amend debugging code for sockets. Add a flag that will help the http wrapper optimize itself when it is not being used for include/require. Index: php4/main/main.c diff -u php4/main/main.c:1.444 php4/main/main.c:1.445 --- php4/main/main.c:1.444 Wed Apr 10 18:42:28 2002 +++ php4/main/main.c Mon Apr 29 20:16:00 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.444 2002/04/10 22:42:28 wez Exp $ */ +/* $Id: main.c,v 1.445 2002/04/30 00:16:00 wez Exp $ */ /* {{{ includes */ @@ -963,6 +963,11 @@ REGISTER_INI_ENTRIES(); + if (php_iface_init(TSRMLS_C) == FAILURE) { + php_printf("PHP: Unable to initialize interface subsystem.\n"); + return FAILURE; + } + /* initialize stream wrappers registry * (this uses configuration parameters from php.ini) */ @@ -1072,6 +1077,7 @@ zend_shutdown(TSRMLS_C); php_shutdown_stream_wrappers(TSRMLS_C); + php_iface_shutdown(TSRMLS_C); php_shutdown_info_logos(); UNREGISTER_INI_ENTRIES(); Index: php4/main/network.c diff -u php4/main/network.c:1.48 php4/main/network.c:1.49 --- php4/main/network.c:1.48 Fri Apr 19 06:06:41 2002 +++ php4/main/network.c Mon Apr 29 20:16:00 2002 @@ -15,8 +15,9 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: network.c,v 1.48 2002/04/19 10:06:41 wez Exp $ */ +/* $Id: network.c,v 1.49 2002/04/30 00:16:00 wez Exp $ */ +/*#define DEBUG_MAIN_NETWORK 1*/ #define MAX_CHUNKS_PER_READ 10 #include "php.h" @@ -591,7 +592,7 @@ #if ZEND_DEBUG && DEBUG_MAIN_NETWORK static inline void dump_sock_state(char *msg, php_netstream_data_t *sock TSRMLS_DC) { - printf("%s: blocked=%d timeout_event=%d eof=%d inbuf=%d\n", msg, sock->is_blocked, sock->timeout_event, sock->eof, TOREAD(sock)); + printf("%s: blocked=%d timeout_event=%d eof=%d inbuf=%d timeout=%d\n", msg, sock->is_blocked, sock->timeout_event, sock->eof, TOREAD(sock), sock->timeout); } # define DUMP_SOCK_STATE(msg, sock) dump_sock_state(msg, sock TSRMLS_CC) #else @@ -600,7 +601,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data_t *sock TSRMLS_DC) { - fd_set fdr, tfdr; + fd_set fdr, tfdr, fdx; int retval; struct timeval timeout, *ptimeout; @@ -616,11 +617,12 @@ while(1) { tfdr = fdr; + fdx = fdr; timeout = sock->timeout; DUMP_SOCK_STATE("wait_for_data", sock); - retval = select(sock->socket + 1, &tfdr, NULL, NULL, ptimeout); + retval = select(sock->socket + 1, &tfdr, NULL, &fdx, ptimeout); if (retval == 0) sock->timeout_event = 1; @@ -664,6 +666,10 @@ nr_bytes = recv(sock->socket, buf, sock->chunk_size, 0); DUMP_SOCK_STATE("read_internal after recv/SSL_read", sock); +#if DEBUG_MAIN_NETWORK +printf("read_internal read %d/%d bytes\n", nr_bytes, sock->chunk_size); +#endif + if(nr_bytes > 0) { php_stream_notify_progress_increment(stream->context, nr_bytes, 0); @@ -768,7 +774,10 @@ memcpy(buf, READPTR(sock), ret); sock->readpos += ret; } - +#if DEBUG_MAIN_NETWORK + DUMP_SOCK_STATE("sockop_read", sock); + printf("sockop_read returning with %d bytes read\n", ret); +#endif return ret; } Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.31 php4/main/php_streams.h:1.32 --- php4/main/php_streams.h:1.31 Tue Apr 16 18:14:27 2002 +++ php4/main/php_streams.h Mon Apr 29 20:16:00 2002 @@ -119,7 +119,7 @@ struct _php_stream_context { php_stream_notifier *notifier; - + zval *options; /* hash keyed by wrapper family or specific wrapper */ }; typedef struct _php_stream_wrapper_options { @@ -352,6 +352,14 @@ /* If you don't need to write to the stream, but really need to * be able to seek, use this flag in your options. */ #define STREAM_MUST_SEEK 16 +/* If you are going to end up casting the stream into a FILE* or + * a socket, pass this flag and the streams/wrappers will not use + * buffering mechanisms while reading the headers, so that HTTP + * wrapped streams will work consistently. + * If you omit this flag, streams will use buffering and should end + * up working more optimally. + * */ +#define STREAM_WILL_CAST 32 #ifdef PHP_WIN32 # define IGNORE_URL_WIN IGNORE_URL @@ -390,6 +398,10 @@ PHPAPI void php_stream_context_free(php_stream_context *context); PHPAPI php_stream_context *php_stream_context_alloc(void); +PHPAPI int php_stream_context_get_option(php_stream_context *context, + 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 php_stream_notifier *php_stream_notification_alloc(void); PHPAPI void php_stream_notification_free(php_stream_notifier *notifier); Index: php4/main/streams.c diff -u php4/main/streams.c:1.50 php4/main/streams.c:1.51 --- php4/main/streams.c:1.50 Fri Apr 19 06:06:41 2002 +++ php4/main/streams.c Mon Apr 29 20:16:00 2002 @@ -1360,7 +1360,7 @@ FILE *fp = NULL; php_stream *stream = NULL; - stream = php_stream_open_wrapper_rel(path, mode, options, opened_path); + stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, opened_path); if (stream == NULL) return NULL; @@ -1428,12 +1428,19 @@ PHPAPI void php_stream_context_free(php_stream_context *context) { + zval_ptr_dtor(&context->options); efree(context); } PHPAPI php_stream_context *php_stream_context_alloc(void) { - return ecalloc(1, sizeof(php_stream_context)); + php_stream_context *context; + + context = ecalloc(1, sizeof(php_stream_context)); + MAKE_STD_ZVAL(context->options); + array_init(context->options); + + return context; } PHPAPI php_stream_notifier *php_stream_notification_alloc(void) @@ -1444,6 +1451,41 @@ PHPAPI void php_stream_notification_free(php_stream_notifier *notifier) { efree(notifier); +} + +PHPAPI int php_stream_context_get_option(php_stream_context *context, + const char *wrappername, const char *optionname, zval **optionvalue) +{ + zval **wrapperhash; + + if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) + return FAILURE; + + return zend_hash_find(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&optionvalue); +} + +PHPAPI int php_stream_context_set_option(php_stream_context *context, + const char *wrappername, const char *optionname, zval *optionvalue) +{ + zval **wrapperhash; + +printf("set option %s:%s:%p\n", wrappername, optionname, optionvalue); + + if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { + // Create the entry here + +printf("creating a zval for wrapper:%s\n", wrappername); + + MAKE_STD_ZVAL(*wrapperhash); + array_init(*wrapperhash); + if (FAILURE == zend_hash_update(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)wrapperhash, sizeof(zval *), NULL)) + return FAILURE; + + ZVAL_ADDREF(optionvalue); + } +printf("storing value with key %s in wrapper hash\n", optionname); + + return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&optionvalue, sizeof(zval *), NULL); }

« previous php.cvs (#11542) next »