* 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;
* 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) {
#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
#endif
/* }}} */
-
-
-
-
/* {{{ php_stream_cast */
PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC)
{
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;
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",
}
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);
return FAILURE;
}
return SUCCESS;
+ case PHP_STREAM_AS_FD_FOR_SELECT:
case PHP_STREAM_AS_FD:
case PHP_STREAM_AS_SOCKETD:
if (ret)