Browse Source

Merge selectable descriptor casting from PHP_4_3 branch.

PEAR_1_4DEV
Wez Furlong 23 years ago
parent
commit
5ecc91c27d
  1. 4
      ext/standard/streamsfuncs.c
  2. 2
      main/php_streams.h
  3. 10
      main/streams/cast.c
  4. 10
      main/streams/plain_wrapper.c
  5. 1
      main/streams/xp_socket.c

4
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) {

2
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

10
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",

10
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);

1
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)

Loading…
Cancel
Save