* 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)
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;
#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
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);
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;