From: Wez Furlong Date: Sat, 28 Jun 2003 11:24:47 +0000 (+0000) Subject: Merge selectable descriptor casting from PHP_4_3 branch. X-Git-Tag: php-5.0.0b1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ecc91c27d1faa7b1917241c71f5f9f82746f985;p=php Merge selectable descriptor casting from PHP_4_3 branch. --- diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index f0eb73a914..74d7701d2d 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -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) { diff --git a/main/php_streams.h b/main/php_streams.h index 58bb7e1609..510ebae2b4 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -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 diff --git a/main/streams/cast.c b/main/streams/cast.c index 81e347a842..3d31f86433 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -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", diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 75bfd27f5c..06909895e5 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -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); diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index c87300b14e..1663a85ffa 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -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)