cvs: php4 /ext/sockets config.m4 sockets.c
| From: | Chris Vandomelen | Date: | Sun, 22 Oct 2000 06:45:03 +0000 |
| Subject: | cvs: php4 /ext/sockets config.m4 sockets.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2206@lists.php.net to get a copy of this message | ||
chrisv Sat Oct 21 23:45:03 2000 EDT
Modified files:
/php4/ext/sockets config.m4 sockets.c
Log:
Corrected some bugs dealing with compile failures (should now compile
on most varieties of Linux, and should hopefully fix at least 3 of the
compile errors that were discovered). Also modified read() slightly
to take an optional parameter as to whether the data was binary or
text so it wouldn't stop reading on a newline or null byte received.
@- Made read() binary-safe in sockets.c (Chris Vandomelen)
@- Attempted fixing some compile failures (Chris Vandomelen)
# Hopefully someone will attempt to compile this on other systems, I
# have no access to other platforms to compile it on ....
Index: php4/ext/sockets/config.m4
diff -u php4/ext/sockets/config.m4:1.3 php4/ext/sockets/config.m4:1.4
--- php4/ext/sockets/config.m4:1.3 Mon Oct 2 10:35:58 2000
+++ php4/ext/sockets/config.m4 Sat Oct 21 23:45:03 2000
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.3 2000/10/02 17:35:58 rasmus Exp $
+dnl $Id: config.m4,v 1.4 2000/10/22 06:45:03 chrisv Exp $
dnl config.m4 for extension sockets
dnl don't forget to call PHP_EXTENSION(sockets)
@@ -31,7 +31,6 @@
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h netinet/in.h netinet/tcp.h sys/un.h
arpa/inet.h)
AC_CHECK_HEADERS(sys/time.h errno.h fcntl.h)
-
AC_DEFINE(HAVE_SOCKETS, 1, [ ])
dnl Write more examples of tests here...
PHP_EXTENSION(sockets, $ext_shared)
Index: php4/ext/sockets/sockets.c
diff -u php4/ext/sockets/sockets.c:1.15 php4/ext/sockets/sockets.c:1.16
--- php4/ext/sockets/sockets.c:1.15 Fri Oct 20 11:25:12 2000
+++ php4/ext/sockets/sockets.c Sat Oct 21 23:45:03 2000
@@ -17,13 +17,19 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sockets.c,v 1.15 2000/10/20 18:25:12 andrei Exp $ */
+/* $Id: sockets.c,v 1.16 2000/10/22 06:45:03 chrisv Exp $ */
#include "php.h"
#if HAVE_SOCKETS
+/* This hopefully will fix some compile errors on other platforms --
+ * the usage of msg_control/msg_controllen are X/Open Extended attributes,
+ * or so it seems, by reading HP/UX 10.20 manual pages. */
+
+#define _XOPEN_SOURCE_EXTENDED
+
#include "ext/standard/info.h"
#include "php_sockets.h"
@@ -47,6 +53,19 @@
php_sockets_globals sockets_globals;
#endif
+/* It seems some platforms don't have this... */
+
+#ifndef MSG_WAITALL
+#ifdef LINUX
+/* Well, it's defined on linux to this, and on a few
+ * distributions, it doesn't get included... */
+#define MSG_WAITALL 0x00000100
+#else
+#define MSG_WAITALL 0x00000000
+#endif
+#endif
+
+
/* Perform convert_to_long_ex on a list of items */
static void v_convert_to_long_ex(int items,...)
{
@@ -151,14 +170,14 @@
static void destroy_fd_sets(zend_rsrc_list_entry *rsrc)
{
- fd_set *set = (fd_set *)rsrc->ptr;
+ fd_set *set = (fd_set *) rsrc->ptr;
efree(set);
}
static void destroy_iovec(zend_rsrc_list_entry *rsrc)
{
- php_iovec_t *iov = (php_iovec_t *)rsrc->ptr;
int i;
+ php_iovec_t *iov = (php_iovec_t *) rsrc->ptr;
if (iov->count && iov->iov_array) {
for (i = 0; i < iov->count; i++) {
@@ -576,20 +595,36 @@
}
/* }}} */
-/* {{{ proto int read(int fd, string &buf, int length)
+/* {{{ proto int read(int fd, string &buf, int length [, int binary])
Reads length bytes from fd into buf */
/* php_read -- wrapper around read() so that it only reads to a \r, \n, or \0. */
-int php_read(int fd, void *buf, int maxlen)
+int php_read(int fd, void *buf, int maxlen, int binary)
{
char *t;
int m = 0, n = 0;
int no_read = 0;
-
+ int nonblock = 0;
+ int keep_going = 1;
errno = 0;
+
+ m = fcntl(fd, F_GETFL);
+ if (m == -1)
+ return -1;
+
+ if (m & O_NONBLOCK)
+ nonblock = 1;
+
+ {
+ char buf[255];
+ snprintf(buf, 255, "nonblock = %i\n", nonblock);
+ PUTS(buf);
+ }
+
t = (char *) buf;
- while (*t != '\n' && *t != '\r' && *t != '\0'
&& n < maxlen) {
+ while (keep_going) { /* (*t != '\n' && *t != '\r' && *t !=
'\0' && n < maxlen) { */
+ m = read(fd, (void *) t, 1);
if (m > 0) {
t++;
n++;
@@ -600,26 +635,35 @@
return -1;
}
}
- m = read(fd, (void *) t, 1);
if (errno != 0 && errno != ESPIPE && errno != EAGAIN) {
return -1;
}
errno = 0;
+ if (!binary) {
+ if (*t == '\n' || *t == '\r' || *t == '\0') {
+ keep_going = 0;
+ }
+ }
+ if (n == maxlen)
+ keep_going = 0;
+ if (m == 0 && nonblock)
+ keep_going = 0;
}
return n;
}
PHP_FUNCTION(read)
{
- zval **fd, **buf, **length;
+ zval **fd, **buf, **length, **binary;
char *tmpbuf;
int ret;
- if (ZEND_NUM_ARGS() != 3 ||
- zend_get_parameters_ex(3, &fd, &buf, &length) == FAILURE) {
+ if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 4 ||
+ zend_get_parameters_ex(ZEND_NUM_ARGS(), &fd, &buf, &length, &binary) ==
FAILURE) {
WRONG_PARAM_COUNT;
}
- v_convert_to_long_ex(2, fd, length);
+
+ v_convert_to_long_ex(ZEND_NUM_ARGS() - 1, fd, length, binary);
convert_to_string_ex(buf);
tmpbuf = emalloc(Z_LVAL_PP(length)*sizeof(char));
@@ -628,7 +672,7 @@
RETURN_FALSE;
}
- ret = php_read(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length));
+ ret = php_read(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length), ZEND_NUM_ARGS() == 4 ? Z_LVAL_PP(binary)
: 0);
if (ret >= 0) {
Z_STRVAL_PP(buf) = estrndup(tmpbuf,ret);
@@ -1289,7 +1333,7 @@
efree(recv_buf);
RETURN_LONG(-errno);
} else {
- if (Z_STRVAL_PP(buf) != NULL) {
+ if (Z_STRLEN_PP(buf) > 0) {
efree(Z_STRVAL_PP(buf));
}
Z_STRVAL_PP(buf) = estrndup(recv_buf, strlen(recv_buf));
@@ -1357,6 +1401,11 @@
if (ret < 0) {
RETURN_LONG(-errno);
}
+
+ if (Z_LVAL_PP(flags) & 0xf0000000) {
+ Z_LVAL_PP(flags) &= ~0xf0000000;
+ php_error(E_WARNING, "This platform does not support the MSG_WAITALL flag..");
+ }
switch (sa.sa_family)
{
@@ -1580,6 +1629,12 @@
if (ZEND_NUM_ARGS() == 7) {
convert_to_long_ex(port);
}
+
+ if (Z_LVAL_PP(flags) & 0xf0000000) {
+ Z_LVAL_PP(flags) &= ~0xf0000000;
+ php_error(E_WARNING, "This platform does not support the MSG_WAITALL flag..");
+ }
+
ZEND_FETCH_RESOURCE(iov, php_iovec_t *, iovec, -1, "IO vector table", SOCKETSG(le_iov));