]> granicus.if.org Git - php/commitdiff
add basic stuff to generalize IO
authorAnatol Belski <ab@php.net>
Sat, 18 Oct 2014 22:12:23 +0000 (00:12 +0200)
committerAnatol Belski <ab@php.net>
Sat, 18 Oct 2014 22:12:23 +0000 (00:12 +0200)
config.m4
config.w32
phpdbg_io.c [new file with mode: 0644]
phpdbg_io.h [new file with mode: 0644]

index aea509eb00a0fc4c63b1fc99cbcf8181a0aa2479..3bedc3cad994ddd034b36a5bec76f9778bbd6d0d 100644 (file)
--- a/config.m4
+++ b/config.m4
@@ -33,7 +33,7 @@ if test "$BUILD_PHPDBG" == "" && test "$PHP_PHPDBG" != "no"; then
   fi
 
   PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE"
-  PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_wait.c"
+  PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c"
 
   if test "$PHP_READLINE" != "no" -o  "$PHP_LIBEDIT" != "no"; then
        PHPDBG_EXTRA_LIBS="$PHP_READLINE_LIBS"
index 86f8949cd0d0207202ab0208340ada1ec6454eac..df75510be428642f60babbc4f5a4cd353cc56f2a 100644 (file)
@@ -4,7 +4,7 @@ ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no');
 PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' +
                'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' +
                'phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c '+
-               'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_wait.c';
+               'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c';
 PHPDBG_DLL='php' + PHP_VERSION + 'phpdbg.dll';
 PHPDBG_EXE='phpdbg.exe';
 
diff --git a/phpdbg_io.c b/phpdbg_io.c
new file mode 100644 (file)
index 0000000..e561174
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2014 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Authors: Anatol Belski <ab@php.net>                                  |
+   +----------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "phpdbg_io.h"
+
+PHPDBG_API int
+phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo)
+{/*{{{*/
+       int got_now, i = len, j;
+       char *p = ptr;
+#ifndef PHP_WIN32
+       struct pollfd pfd;
+
+       pfd.fd = sock;
+       pfd.events = POLLIN;
+
+       j = poll(&pfd, 1, tmo);
+
+       if (j == 0) {
+#else
+       struct fd_set readfds;
+       struct timeval ttmo;
+
+       FD_ZERO(&readfds);
+       FD_SET(sock, &readfds);
+
+       ttmo.tv_sec = 0;
+       ttmo.tv_usec = tmo*1000;
+
+       j = select(0, &readfds, NULL, NULL, &ttmo);
+
+       if (j <= 0) {
+#endif
+               return -1;
+       }
+
+       while(i > 0) {
+               got_now = recv(sock, p, i, 0);
+               if (got_now == -1) {
+                       return -1;
+               }
+               i -= got_now;
+               p += got_now;
+       }
+
+       return len;
+}/*}}}*/
+
+PHPDBG_API int
+phpdbg_send_bytes(int sock, char *ptr, int len)
+{/*{{{*/
+       int sent, i = len;
+       char *p = ptr;
+
+       while(i > 0) {
+               sent = send(sock, p, i, 0);
+               if (sent == -1) {
+                       return -1;
+               }
+               i -= sent;
+               p += sent;
+       }
+
+       return len;
+}/*}}}*/
+
diff --git a/phpdbg_io.h b/phpdbg_io.h
new file mode 100644 (file)
index 0000000..e293516
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 5                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2014 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Authors: Anatol Belski <ab@php.net>                                  |
+   +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_IO_H
+#define PHPDBG_IO_H
+
+#include "phpdbg.h"
+
+#ifdef PHP_WIN32
+#undef UNICODE
+#include "win32/inet.h"
+#include <winsock2.h>
+#include <windows.h>
+#include <Ws2tcpip.h>
+#include "win32/sockets.h"
+
+#else
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#include <sys/socket.h>
+#include <netinet/in.h>
+#if HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <netdb.h>
+
+#include <fcntl.h>
+
+#include <poll.h>
+#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);
+
+#endif /* PHPDBG_IO_H */
+