]> granicus.if.org Git - php/commitdiff
Merge selectable descriptor casting from PHP_4_3 branch.
authorWez Furlong <wez@php.net>
Sat, 28 Jun 2003 11:24:47 +0000 (11:24 +0000)
committerWez Furlong <wez@php.net>
Sat, 28 Jun 2003 11:24:47 +0000 (11:24 +0000)
ext/standard/streamsfuncs.c
main/php_streams.h
main/streams/cast.c
main/streams/plain_wrapper.c
main/streams/xp_socket.c

index f0eb73a91443acd486927e8dedf459d4b4e3fb96..74d7701d2d47cd0981948baf2cdc92880fd3eaa9 100644 (file)
@@ -422,7 +422,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
                 * when casting.  It is only used here so that the buffered data warning
                 * is not displayed.
                 * */
-               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1)) {
+               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1)) {
                        FD_SET(this_fd, fds);
                        if (this_fd > *max_fd) {
                                *max_fd = this_fd;
@@ -458,7 +458,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
                 * when casting.  It is only used here so that the buffered data warning
                 * is not displayed.
                 */
-               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1)) {
+               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1)) {
                        if (FD_ISSET(this_fd, fds)) {
                                zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem);
                                if (dest_elem) {
index 58bb7e16093bb6a7941e61b91ecb4e997a9d6d42..510ebae2b46271af0e5b1d3066adc5bc30d9c948 100755 (executable)
@@ -388,6 +388,8 @@ PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC);
 #define PHP_STREAM_AS_FD               1
 /* cast as a socketd */
 #define PHP_STREAM_AS_SOCKETD  2
+/* cast as fd/socket for select purposes */
+#define PHP_STREAM_AS_FD_FOR_SELECT 3
 
 /* try really, really hard to make sure the cast happens (avoid using this flag if possible) */
 #define PHP_STREAM_CAST_TRY_HARD       0x80000000
index 81e347a84227511523fe3db394d1a5342359269c..3d31f86433d943b4559b019f192c1cddf8329c74 100644 (file)
@@ -137,10 +137,6 @@ static COOKIE_IO_FUNCTIONS_T stream_cookie_functions =
 #endif
 /* }}} */
 
-
-
-
-
 /* {{{ php_stream_cast */
 PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC)
 {
@@ -148,7 +144,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
        castas &= ~PHP_STREAM_CAST_MASK;
 
        /* synchronize our buffer (if possible) */
-       if (ret) {
+       if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) {
                php_stream_flush(stream);
                if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) {
                        off_t dummy;
@@ -248,8 +244,8 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
 
        if (show_err) {
                /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */
-               static const char *cast_names[3] = {
-                       "STDIO FILE*", "File Descriptor", "Socket Descriptor"
+               static const char *cast_names[4] = {
+                       "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor"
                };
 
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s",
index 75bfd27f5c6b7feb1749bf2be8ae78972c54e150..06909895e5c7c9f218002f0cbea930629fe9e591 100644 (file)
@@ -523,6 +523,16 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
                        }
                        return SUCCESS;
 
+               case PHP_STREAM_AS_FD_FOR_SELECT:
+                       PHP_STDIOP_GET_FD(fd, data);
+                       if (fd < 0) {
+                               return FAILURE;
+                       }
+                       if (ret) {
+                               *(int*)ret = fd;
+                       }
+                       return SUCCESS;
+
                case PHP_STREAM_AS_FD:
                        PHP_STDIOP_GET_FD(fd, data);
 
index c87300b14edd785702c517bd5579eb96999b8284..1663a85ffa6debd581299df6e7b14cd5d1771be6 100644 (file)
@@ -282,6 +282,7 @@ static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
                                return FAILURE;
                        }
                        return SUCCESS;
+               case PHP_STREAM_AS_FD_FOR_SELECT:
                case PHP_STREAM_AS_FD:
                case PHP_STREAM_AS_SOCKETD:
                        if (ret)