diff options
author | Andrei Zmievski <andrei@php.net> | 2000-02-01 20:02:44 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2000-02-01 20:02:44 +0000 |
commit | a753430fb980a8fa156af9fad61a7daf1618b2ec (patch) | |
tree | fadc29f487ef484f04e81655a7aba4678456e722 /ext | |
parent | 5cabf74445a9717f85579af9ae2d069d693870c9 (diff) | |
download | php-git-a753430fb980a8fa156af9fad61a7daf1618b2ec.tar.gz |
- 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)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/file.c | 58 | ||||
-rw-r--r-- | ext/standard/file.h | 6 | ||||
-rw-r--r-- | ext/standard/fsock.c | 23 | ||||
-rw-r--r-- | ext/standard/fsock.h | 20 |
4 files changed, 80 insertions, 27 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index 145c92589b..ba97256db8 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -241,10 +241,14 @@ function_entry file_functions[] = { 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 @@ PHP_FUNCTION(feof) } } /* }}} */ -/* {{{ 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 @@ PHPAPI int php_set_sock_blocking(int socketd, int block) 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_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 @@ PHP_FUNCTION(set_socket_timeout) #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 @@ PHP_FUNCTION(fgetcsv) { /* }}} */ /* {{{ 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; } diff --git a/ext/standard/file.h b/ext/standard/file.h index e0e05cf98f..b05e980192 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -63,8 +63,10 @@ PHP_FUNCTION(umask); 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); diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 0358e9e391..f13ed2d323 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -103,23 +103,6 @@ function_entry fsock_functions[] = { {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", @@ -466,6 +449,12 @@ static php_sockbuf *php_sockcreate(int socket FLS_DC) return sock; } +PHPAPI php_sockbuf *php_get_socket(int socket) +{ + SOCK_FIND(sock, socket); + return sock; +} + size_t php_sock_set_def_chunk_size(size_t size) { size_t old; diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h index 24bbef6810..ff6c85d5b3 100644 --- a/ext/standard/fsock.h +++ b/ext/standard/fsock.h @@ -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 @@ size_t php_sock_set_def_chunk_size(size_t size); 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); |