]> granicus.if.org Git - php/commitdiff
Fix erroneous error status when attempting to use stream_select() on an SSL
authorWez Furlong <wez@php.net>
Tue, 13 May 2003 00:18:27 +0000 (00:18 +0000)
committerWez Furlong <wez@php.net>
Tue, 13 May 2003 00:18:27 +0000 (00:18 +0000)
stream.  As a by-product, this also fixes Bug #22238, stream_select() clobbers
read buffer for pipes.

ext/standard/file.c
main/network.c
main/php_streams.h
main/streams.c

index f3dd39e7d00c81d90ecdb69f042b6adf92e57542..35691a34e9ae5030b706d95390ec9953e59553b7 100644 (file)
@@ -657,7 +657,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, int *max_fd 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;
@@ -693,7 +693,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 a25218cb6ab07ff68d882c571b85863c3e4893f3..c4c24ebb7bd597f95c75c52e26ec5adaabe1dd05 100644 (file)
@@ -1137,24 +1137,29 @@ static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
        switch(castas)  {
                case PHP_STREAM_AS_STDIO:
 #if HAVE_OPENSSL_EXT
-                       if (sock->ssl_active)
+                       if (sock->ssl_active) {
                                return FAILURE;
+                       }
 #endif
-                       if (ret)        {
+                       if (ret) {
                                *(FILE**)ret = fdopen(sock->socket, stream->mode);
-                               if (*ret)
+                               if (*ret) {
                                        return SUCCESS;
+                               }
                                return FAILURE;
                        }
                        return SUCCESS;
                case PHP_STREAM_AS_FD:
                case PHP_STREAM_AS_SOCKETD:
 #if HAVE_OPENSSL_EXT
-                       if (sock->ssl_active)
+                       if (sock->ssl_active) {
                                return FAILURE;
+                       }
 #endif
-                       if (ret)
+               case PHP_STREAM_AS_FD_FOR_SELECT:
+                       if (ret) {
                                *(int*)ret = sock->socket;
+                       }
                        return SUCCESS;
                default:
                        return FAILURE;
index 37ff5f3e059d02d02902d4978809953eac59a101..01dfa2cfd6eae187311e9ba595928802db7d89a1 100755 (executable)
@@ -462,6 +462,8 @@ PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char
 #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 d99014d6393b110271e05d9942625442bfb9e9e3..5776a0e3264a0e8636e18bd7d5c6151179b4809b 100755 (executable)
@@ -1563,6 +1563,16 @@ static int php_stdiop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
                                data->fd = -1;
                        }
                        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);
@@ -2112,7 +2122,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;