]> granicus.if.org Git - php/commitdiff
Implement context option setting API.
authorWez Furlong <wez@php.net>
Tue, 30 Apr 2002 00:16:00 +0000 (00:16 +0000)
committerWez Furlong <wez@php.net>
Tue, 30 Apr 2002 00:16:00 +0000 (00:16 +0000)
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.

main/main.c
main/network.c
main/php_streams.h
main/streams.c

index 737507ac1d0ea54e61bd422ef7b4e7364c5c2493..afcb7c47d90c00076adec1cc2b5d9b9659d9ea9e 100644 (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();
index a34244e84ecf785f501f3444ecbceb8d00caf619..3a7cb6a6a0162141eb8fc8c00f9c3b5e5311ba6e 100644 (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;
 }
 
index af1bcefc23913835dbce28d59e458b9d0ec3cc1a..815b0ea549ff6a1a262447846bc6503d9ad5ef31 100755 (executable)
@@ -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);
index 3af18e25b9b15ecd9c2d0eee75004845e7e98df9..06b549c1d34181465522bbcc60791393d67f65ec 100755 (executable)
@@ -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: