From 1137d9cb2bb269d73708b76349a07c36bcac13dc Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 19 Oct 2014 01:32:46 +0200 Subject: [PATCH] several fixes to the new io stuff --- phpdbg_io.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- phpdbg_io.h | 32 ++++++------------------------ 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/phpdbg_io.c b/phpdbg_io.c index e561174f8c..f358fbfcd8 100644 --- a/phpdbg_io.c +++ b/phpdbg_io.c @@ -22,6 +22,35 @@ #include "phpdbg_io.h" +#ifdef PHP_WIN32 +#undef UNICODE +#include "win32/inet.h" +#include +#include +#include +#include "win32/sockets.h" + +#else + +#if HAVE_SYS_TYPES_H +#include +#endif +#include +#include +#if HAVE_ARPA_INET_H +#include +#endif +#include + +#include + +#include +#endif + + +ZEND_EXTERN_MODULE_GLOBALS(phpdbg); + + PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) {/*{{{*/ @@ -54,6 +83,11 @@ phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) } while(i > 0) { +#ifdef PHP_WIN32 + int can_read = recv(sock, p, i, MSG_PEEK); + + i = can_read; +#endif got_now = recv(sock, p, i, 0); if (got_now == -1) { return -1; @@ -62,7 +96,7 @@ phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) p += got_now; } - return len; + return p - ptr; }/*}}}*/ PHPDBG_API int @@ -83,3 +117,24 @@ phpdbg_send_bytes(int sock, char *ptr, int len) return len; }/*}}}*/ + +PHPDBG_API int +phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_CC) +{/*{{{*/ + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { + return phpdbg_consume_bytes(sock, ptr, len, tmo); + } + + return read(sock, ptr, len); +}/*}}}*/ + + +PHPDBG_API int +phpdbg_mixed_write(int sock, char *ptr, int len TSRMLS_CC) +{/*{{{*/ + if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) { + return phpdbg_send_bytes(sock, ptr, len); + } + + return write(sock, ptr, len); +}/*}}}*/ diff --git a/phpdbg_io.h b/phpdbg_io.h index e293516777..3c4684698a 100644 --- a/phpdbg_io.h +++ b/phpdbg_io.h @@ -21,37 +21,17 @@ #include "phpdbg.h" -#ifdef PHP_WIN32 -#undef UNICODE -#include "win32/inet.h" -#include -#include -#include -#include "win32/sockets.h" - -#else - -#if HAVE_SYS_TYPES_H -#include -#endif -#include -#include -#if HAVE_ARPA_INET_H -#include -#endif -#include - -#include - -#include -#endif - - PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo); PHPDBG_API int phpdbg_send_bytes(int sock, char *ptr, int len); +PHPDBG_API int +phpdbg_mixed_read(int sock, char *ptr, int len, int tmo TSRMLS_CC); + +PHPDBG_API int +phpdbg_mixed_write(int sock, char *ptr, int len TSRMLS_CC); + #endif /* PHPDBG_IO_H */ -- 2.40.0