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.
This commit is contained in:
Wez Furlong 2002-04-30 00:16:00 +00:00
parent 94f9b3bdb5
commit 37411dd674
4 changed files with 76 additions and 7 deletions

View file

@ -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();

View file

@ -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;
}

View file

@ -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);

View file

@ -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: