cvs: /php4/ext/standard file.h file.c

From: Date: Wed, 24 Nov 1999 03:05:41 +0000
Subject: cvs: /php4/ext/standard file.h file.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-6814@lists.php.net to get a copy of this message
evan Tue Nov 23 22:05:41 1999 EDT Modified files: /php4/ext/standard file.h file.c Log: First attempt at fd_set() and select() # Please test thoroughly Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.12 php4/ext/standard/file.h:1.13 --- php4/ext/standard/file.h:1.12 Sun Nov 14 06:05:37 1999 +++ php4/ext/standard/file.h Tue Nov 23 22:05:10 1999 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.12 1999/11/14 11:05:37 ssb Exp $ */ +/* $Id: file.h,v 1.13 1999/11/24 03:05:10 evan Exp $ */ /* Synced with php3 revision 1.30 1999-06-16 [ssb] */ @@ -68,6 +68,8 @@ PHP_FUNCTION(set_file_buffer); PHP_FUNCTION(get_meta_tags); PHP_FUNCTION(flock); +PHP_FUNCTION(fd_set); +PHP_FUNCTION(select); PHPAPI int _php3_set_sock_blocking(int socketd, int block); PHPAPI int php_file_le_fopen(void); Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.39 php4/ext/standard/file.c:1.40 --- php4/ext/standard/file.c:1.39 Sun Nov 14 06:05:37 1999 +++ php4/ext/standard/file.c Tue Nov 23 22:05:10 1999 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.39 1999/11/14 11:05:37 ssb Exp $ */ +/* $Id: file.c,v 1.40 1999/11/24 03:05:10 evan Exp $ */ /* Synced with php3 revision 1.218 1999-06-16 [ssb] */ @@ -111,6 +111,9 @@ /* sharing globals is *evil* */ static int le_fopen,le_popen, le_socket, le_uploads; +static fd_set readfd; +static int max_fd; + /* }}} */ /* {{{ tempnam */ @@ -241,6 +244,8 @@ #if (0 && defined(HAVE_SYS_TIME_H) && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)) PHP_FE(set_socket_timeout, NULL) #endif + PHP_FE(fd_set, NULL) + PHP_FE(select, NULL) {NULL, NULL, NULL} }; @@ -1661,9 +1666,70 @@ /* }}} */ -/*< - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ +PHP_FUNCTION(fd_set) +{ + pval **arg; + void *what; + int type, fd; + + if(ARG_COUNT(ht) <= 0) { + php_error(E_WARNING, "fd_set: Must be passed at least one value" ); + var_uninit(return_value); + return; + } + else if(ARG_COUNT(ht) == 1) { + if(getParametersEx(1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + what = zend_fetch_resource(arg,-1,"Select",&type,3,le_fopen,le_socket,le_popen); + ZEND_VERIFY_RESOURCE(what); + if(type == le_socket) { + fd = *(int *)what; + } else { + fd = fileno((FILE *)what); + } + max_fd = fd; + FD_ZERO(&readfd); + FD_SET(max_fd, &readfd); + } + else { + pval ***args = (pval ***) emalloc(sizeof(pval **) * ARG_COUNT(ht)); + pval **max, result; + int i; + if(getParametersArrayEx(ARG_COUNT(ht), args) == FAILURE) { + efree(args); + WRONG_PARAM_COUNT; + } + FD_ZERO(&readfd); + for(i = 0; i < ARG_COUNT(ht); i++) { + what = zend_fetch_resource(*args,-1,"select",&type,3,le_fopen,le_socket,le_popen); + ZEND_VERIFY_RESOURCE(what); + if(type == le_socket) { + fd = *(int *)what; + } else { + fd = fileno((FILE *)what); + } + FD_SET(fd, &readfd); + if(fd > max_fd) max_fd = fd; + } + } + RETURN_LONG(1); +} + +PHP_FUNCTION(select) +{ + pval **timeout; + struct timeval tv; + + if(ARG_COUNT(ht) != 1 || getParametersEx(1, &timeout) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(timeout); + + tv.tv_sec = (*timeout)->value.lval / 1000000; + tv.tv_usec = (*timeout)->value.lval % 1000000; + + RETURN_LONG(select(max_fd + 1,&readfd,NULL,NULL,((*timeout)->value.lval <= 0) ? NULL : &tv)); +} +

« previous php.version4 (#6814) next »