diff options
author | Sean Finney <seanius@debian.org> | 2009-06-24 22:49:04 +0200 |
---|---|---|
committer | Sean Finney <seanius@debian.org> | 2009-06-24 22:49:04 +0200 |
commit | 84f4ca9b07fe5b73d840258f4aa7c1eb534c4253 (patch) | |
tree | 9829bd578af8a4a8b42b04277f9067e00dc5ad90 /sapi/cli/php_cli.c | |
parent | 6821b67124604da690c5e9276d5370d679c63ac8 (diff) | |
download | php-84f4ca9b07fe5b73d840258f4aa7c1eb534c4253.tar.gz |
Imported Upstream version 5.3.0~RC4upstream/5.3.0_RC4upstream/5.3.0.RC4
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r-- | sapi/cli/php_cli.c | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index bafd1a570..edc8f2953 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_cli.c,v 1.129.2.13.2.22.2.21 2009/01/09 17:21:11 iliaa Exp $ */ +/* $Id: php_cli.c,v 1.129.2.13.2.22.2.26 2009/06/05 18:50:32 mattwil Exp $ */ #include "php.h" #include "php_globals.h" @@ -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 size_t sapi_cli_single_write(const char *str, uint str_length) /* {{{ */ +static inline int sapi_cli_select(int fd TSRMLS_DC) +{ + 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 TSRMLS_DC) /* {{{ */ { #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 TSRMLS_CC)); + if (ret <= 0) { return 0; } + return ret; #else size_t ret; @@ -258,7 +287,7 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ while (remaining > 0) { - ret = sapi_cli_single_write(ptr, remaining); + ret = sapi_cli_single_write(ptr, remaining TSRMLS_CC); if (!ret) { #ifndef PHP_CLI_WIN32_NO_CONSOLE php_handle_aborted_connection(); @@ -477,9 +506,9 @@ static void php_cli_usage(char *argv0) " -F <file> Parse and execute <file> for every input line\n" " -E <end_code> Run PHP <end_code> after processing all input lines\n" " -H Hide any passed arguments from external tools.\n" - " -s Display colour syntax highlighted source.\n" + " -s Output HTML syntax highlighted source.\n" " -v Version number\n" - " -w Display source with stripped comments and whitespace.\n" + " -w Output source with stripped comments and whitespace.\n" " -z <file> Load Zend extension <file>.\n" "\n" " args... Arguments passed to script. Use -- args when first argument\n" @@ -1136,11 +1165,11 @@ int main(int argc, char *argv[]) continue; } - zend_eval_string(code, NULL, "php shell code" TSRMLS_CC); + zend_eval_stringl(code, pos, NULL, "php shell code" TSRMLS_CC); pos = 0; if (php_last_char != '\0' && php_last_char != '\n') { - sapi_cli_single_write("\n", 1); + sapi_cli_single_write("\n", 1 TSRMLS_CC); } if (EG(exception)) { |