From: Wez Furlong Date: Tue, 13 May 2003 00:18:27 +0000 (+0000) Subject: Fix erroneous error status when attempting to use stream_select() on an SSL X-Git-Tag: php-4.3.2RC3~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b2f0b8ac4cea6f7a58a569c414512aeedde3348;p=php Fix erroneous error status when attempting to use stream_select() on an SSL stream. As a by-product, this also fixes Bug #22238, stream_select() clobbers read buffer for pipes. --- diff --git a/ext/standard/file.c b/ext/standard/file.c index f3dd39e7d0..35691a34e9 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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) diff --git a/main/network.c b/main/network.c index a25218cb6a..c4c24ebb7b 100644 --- a/main/network.c +++ b/main/network.c @@ -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; diff --git a/main/php_streams.h b/main/php_streams.h index 37ff5f3e05..01dfa2cfd6 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -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 diff --git a/main/streams.c b/main/streams.c index d99014d639..5776a0e326 100755 --- a/main/streams.c +++ b/main/streams.c @@ -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;