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

From: Date: Tue, 01 Feb 2000 20:03:14 +0000
Subject: cvs: /php4 TODO /php4/ext/standard file.c file.h fsock.c fsock.h
Groups: php.version4 
Request: Send a blank email to php-version4+get-9640@lists.php.net to get a copy of this message
andrei Tue Feb 1 21:03:14 2000 EDT Modified files: /php4 TODO /php4/ext/standard file.c file.h fsock.c fsock.h Log: - Implemented socket_get_status() function. Some more stuff can be added to it in the future. - Renamed set_socket_timeout() to socket_set_timeout() - Renamed set_socket_blocking() to socket_set_blocking() but kept the old name for compatibility. It now outputs a warning that set_socket_timeout() is deprecated but still goes through. @ Added socket_get_status() function. Renamed: @ set_socket_timeout() -> socket_set_timeout() @ set_socket_blocking() -> socket_set_blocking(). (Andrei) Index: php4/TODO diff -u php4/TODO:1.39 php4/TODO:1.40 --- php4/TODO:1.39 Tue Feb 1 18:17:08 2000 +++ php4/TODO Tue Feb 1 21:02:43 2000 @@ -49,7 +49,6 @@ ------------ * strpad() (Andrei) * stri_replace() (Andrei) - * socket_get_status() (Andrei) * comparing arrays semantically (like Python) (Andrei) * move socket related functions to fsock.c * NOT binary safe: Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.59 php4/ext/standard/file.c:1.60 --- php4/ext/standard/file.c:1.59 Tue Feb 1 07:06:03 2000 +++ php4/ext/standard/file.c Tue Feb 1 21:02:44 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.59 2000/02/01 06:06:03 andrei Exp $ */ +/* $Id: file.c,v 1.60 2000/02/01 20:02:44 andrei Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -241,10 +241,14 @@ PHP_FE(fgetcsv, NULL) PHP_FE(flock, NULL) PHP_FE(get_meta_tags, NULL) + /* set_socket_blocking() is deprecated, + use socket_set_blocking() instead */ PHP_FE(set_socket_blocking, NULL) + PHP_FE(socket_set_blocking, NULL) #if HAVE_SYS_TIME_H - PHP_FE(set_socket_timeout, NULL) + PHP_FE(socket_set_timeout, NULL) #endif + PHP_FE(socket_get_status, NULL) PHP_FE(realpath, NULL) #if 0 /* needs to be rethought 991221 thies@digicol.de */ PHP_FE(fd_set, NULL) @@ -818,9 +822,10 @@ } } /* }}} */ -/* {{{ proto int set_socket_blocking(int socket descriptor, int mode) - Set blocking/non-blocking mode on a socket */ + +/* {{{ proto int socket_set_blocking(int socket descriptor, int mode) + Set blocking/non-blocking mode on a socket */ PHPAPI int php_set_sock_blocking(int socketd, int block) { int ret = SUCCESS; @@ -851,7 +856,7 @@ return ret; } -PHP_FUNCTION(set_socket_blocking) +PHP_FUNCTION(socket_set_blocking) { pval **arg1, **arg2; int block; @@ -880,11 +885,16 @@ /* }}} */ +PHP_FUNCTION(set_socket_blocking) +{ + php_error(E_NOTICE, "set_socket_blocking() is deprecated, use socket_set_blocking() instead"); + PHP_FN(socket_set_blocking)(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} -/* {{{ proto bool set_socket_timeout(int socket descriptor, int seconds, int microseconds) +/* {{{ proto bool socket_set_timeout(int socket descriptor, int seconds, int microseconds) Set timeout on socket read to seconds + microseonds */ #if HAVE_SYS_TIME_H -PHP_FUNCTION(set_socket_timeout) +PHP_FUNCTION(socket_set_timeout) { zval **socket, **seconds, **microseconds; int type; @@ -918,6 +928,38 @@ #endif /* HAVE_SYS_TIME_H */ /* }}} */ + + +/* {{{ proto array socket_get_status(resource socket_descriptor) + Return an array describing socket status */ +PHP_FUNCTION(socket_get_status) +{ + zval **socket; + int type; + void *what; + int socketd = 0; + struct php_sockbuf *sock; + FLS_FETCH(); + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket) == FAILURE) { + WRONG_PARAM_COUNT; + } + + what = zend_fetch_resource(socket, -1, "File-Handle", &type, 1, le_socket); + ZEND_VERIFY_RESOURCE(what); + socketd = *(int *)what; + sock = php_get_socket(socketd); + + array_init(return_value); + + add_assoc_bool(return_value, "timed_out", sock->timeout_event); + add_assoc_bool(return_value, "blocked", sock->is_blocked); + add_assoc_bool(return_value, "eof", sock->eof); + add_assoc_long(return_value, "unread_bytes", sock->writepos - sock->readpos); +} +/* }}} */ + + /* {{{ proto string fgets(int fp, int length) Get a line from file pointer */ @@ -1691,13 +1733,13 @@ /* }}} */ /* {{{ proto string realpath(string path) - Returns the resolved path */ + Return the resolved path */ PHP_FUNCTION(realpath) { zval **path; char resolved_path[MAXPATHLEN]; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &path) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) { WRONG_PARAM_COUNT; } Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.16 php4/ext/standard/file.h:1.17 --- php4/ext/standard/file.h:1.16 Tue Feb 1 07:06:03 2000 +++ php4/ext/standard/file.h Tue Feb 1 21:02:44 2000 @@ -27,7 +27,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.16 2000/02/01 06:06:03 andrei Exp $ */ +/* $Id: file.h,v 1.17 2000/02/01 20:02:44 andrei Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -63,8 +63,10 @@ PHP_FUNCTION(rename); PHP_FUNCTION(copy); PHP_FUNCTION(file); -PHP_FUNCTION(set_socket_blocking); -PHP_FUNCTION(set_socket_timeout); +PHP_FUNCTION(set_socket_blocking); /* deprecated */ +PHP_FUNCTION(socket_set_blocking); +PHP_FUNCTION(socket_set_timeout); +PHP_FUNCTION(socket_get_status); PHP_FUNCTION(set_file_buffer); PHP_FUNCTION(get_meta_tags); PHP_FUNCTION(flock); Index: php4/ext/standard/fsock.c diff -u php4/ext/standard/fsock.c:1.42 php4/ext/standard/fsock.c:1.43 --- php4/ext/standard/fsock.c:1.42 Fri Jan 28 14:31:12 2000 +++ php4/ext/standard/fsock.c Tue Feb 1 21:02:44 2000 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.42 2000/01/28 13:31:12 zeev Exp $ */ +/* $Id: fsock.c,v 1.43 2000/02/01 20:02:44 andrei Exp $ */ /* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */ /* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */ @@ -103,23 +103,6 @@ {NULL, NULL, NULL} }; -struct php_sockbuf { - int socket; - unsigned char *readbuf; - size_t readbuflen; - size_t readpos; - size_t writepos; - struct php_sockbuf *next; - struct php_sockbuf *prev; - char eof; - char persistent; - char is_blocked; - size_t chunk_size; - struct timeval timeout; - int timeout_event; -}; - -typedef struct php_sockbuf php_sockbuf; zend_module_entry fsock_module_entry = { "Socket functions", @@ -463,6 +446,12 @@ sock->timeout.tv_sec = -1; FG(phpsockbuf) = sock; + return sock; +} + +PHPAPI php_sockbuf *php_get_socket(int socket) +{ + SOCK_FIND(sock, socket); return sock; } Index: php4/ext/standard/fsock.h diff -u php4/ext/standard/fsock.h:1.23 php4/ext/standard/fsock.h:1.24 --- php4/ext/standard/fsock.h:1.23 Mon Jan 17 18:33:21 2000 +++ php4/ext/standard/fsock.h Tue Feb 1 21:02:44 2000 @@ -27,7 +27,7 @@ | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ -/* $Id: fsock.h,v 1.23 2000/01/17 17:33:21 zeev Exp $ */ +/* $Id: fsock.h,v 1.24 2000/02/01 20:02:44 andrei Exp $ */ /* Synced with php 3.0 revision 1.24 1999-06-18 [ssb] */ @@ -58,8 +58,27 @@ extern zend_module_entry fsock_module_entry; #define phpext_fsock_ptr &fsock_module_entry +struct php_sockbuf { + int socket; + unsigned char *readbuf; + size_t readbuflen; + size_t readpos; + size_t writepos; + struct php_sockbuf *next; + struct php_sockbuf *prev; + char eof; + char persistent; + char is_blocked; + size_t chunk_size; + struct timeval timeout; + char timeout_event; +}; + +typedef struct php_sockbuf php_sockbuf; + PHP_FUNCTION(fsockopen); PHP_FUNCTION(pfsockopen); + int lookup_hostname(const char *addr, struct in_addr *in); char *php_sock_fgets(char *buf, size_t maxlen, int socket); size_t php_sock_fread(char *buf, size_t maxlen, int socket); @@ -74,6 +93,7 @@ void php_msock_destroy(int *data); PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, socklen_t addrlen, struct timeval *timeout); +PHPAPI struct php_sockbuf *php_get_socket(int socket); PHP_MINIT_FUNCTION(fsock); PHP_MSHUTDOWN_FUNCTION(fsock);

« previous php.version4 (#9640) next »