diff options
author | Arnaud Le Blanc <lbarnaud@php.net> | 2009-04-07 16:11:19 +0000 |
---|---|---|
committer | Arnaud Le Blanc <lbarnaud@php.net> | 2009-04-07 16:11:19 +0000 |
commit | 95b308949cae138437069c46b9525b5eb0d89175 (patch) | |
tree | 44a9d4960395655d764f128ea8c61cb9918a6f83 /sapi/cli/php_cli.c | |
parent | f0b4c7be5c775879a67cc839b6ea1e94ddd17da3 (diff) | |
download | php-git-95b308949cae138437069c46b9525b5eb0d89175.tar.gz |
MFH: Fixed bug #47893 (CLI aborts on non blocking stdout)
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r-- | sapi/cli/php_cli.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 373c39f2c9..62094dbbef 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -91,6 +91,12 @@ #include "php_getopt.h" +#ifndef PHP_WIN32 +# define php_select(m, r, w, e, t) select(m, r, w, e, t) +#else +# include "win32/select.h" +#endif + PHPAPI extern char *php_ini_opened_path; PHPAPI extern char *php_ini_scanned_files; @@ -224,15 +230,38 @@ static void print_extensions(TSRMLS_D) /* {{{ */ #define STDOUT_FILENO 1 #endif +static inline int sapi_cli_select(int fd) +{ + fd_set wfd, dfd; + struct timeval tv; + int ret; + + FD_ZERO(&wfd); + FD_ZERO(&dfd); + + PHP_SAFE_FD_SET(fd, &wfd); + + tv.tv_sec = FG(default_socket_timeout); + tv.tv_usec = 0; + + ret = php_select(fd+1, &dfd, &wfd, &dfd, &tv); + + return ret != -1; +} + static inline size_t sapi_cli_single_write(const char *str, uint str_length) /* {{{ */ { #ifdef PHP_WRITE_STDOUT long ret; - ret = write(STDOUT_FILENO, str, str_length); + do { + ret = write(STDOUT_FILENO, str, str_length); + } while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO)); + if (ret <= 0) { return 0; } + return ret; #else size_t ret; |