diff options
author | Wez Furlong <wez@php.net> | 2002-04-30 00:16:00 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2002-04-30 00:16:00 +0000 |
commit | 37411dd67427babef896b10c55d8f92ff09c318c (patch) | |
tree | 3b3b27f9f9c6d2e3f97dc2a85c6d730e51a2784d | |
parent | 94f9b3bdb5c5cf05656b63935ff0343cf9aebfb8 (diff) | |
download | php-git-37411dd67427babef896b10c55d8f92ff09c318c.tar.gz |
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.
-rw-r--r-- | main/main.c | 6 | ||||
-rw-r--r-- | main/network.c | 17 | ||||
-rwxr-xr-x | main/php_streams.h | 14 | ||||
-rwxr-xr-x | main/streams.c | 46 |
4 files changed, 76 insertions, 7 deletions
diff --git a/main/main.c b/main/main.c index 737507ac1d..afcb7c47d9 100644 --- a/main/main.c +++ b/main/main.c @@ -963,6 +963,11 @@ int php_module_startup(sapi_module_struct *sf) 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 @@ void php_module_shutdown(TSRMLS_D) zend_shutdown(TSRMLS_C); php_shutdown_stream_wrappers(TSRMLS_C); + php_iface_shutdown(TSRMLS_C); php_shutdown_info_logos(); UNREGISTER_INI_ENTRIES(); diff --git a/main/network.c b/main/network.c index a34244e84e..3a7cb6a6a0 100644 --- a/main/network.c +++ b/main/network.c @@ -17,6 +17,7 @@ */ /* $Id$ */ +/*#define DEBUG_MAIN_NETWORK 1*/ #define MAX_CHUNKS_PER_READ 10 #include "php.h" @@ -591,7 +592,7 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count #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 inline void dump_sock_state(char *msg, php_netstream_data_t *sock TSRMLS_ 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 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data 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 @@ DUMP_SOCK_STATE("read_internal about to recv/SSL_read", sock); 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 @@ DUMP_SOCK_STATE("check for EOF", sock); 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; } diff --git a/main/php_streams.h b/main/php_streams.h index af1bcefc23..815b0ea549 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -119,7 +119,7 @@ typedef struct _php_stream_notifier { 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 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show /* 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 extern php_stream_ops php_stream_userspace_ops; 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); diff --git a/main/streams.c b/main/streams.c index 3af18e25b9..06b549c1d3 100755 --- a/main/streams.c +++ b/main/streams.c @@ -1360,7 +1360,7 @@ PHPAPI FILE * _php_stream_open_wrapper_as_file(char *path, char *mode, int optio 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_notification_notify(php_stream_context *context, int noti 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) @@ -1446,6 +1453,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); +} + /* * Local variables: |