]> granicus.if.org Git - php/commitdiff
- Implemented socket_get_status() function. Some more stuff can be added
authorAndrei Zmievski <andrei@php.net>
Tue, 1 Feb 2000 20:02:44 +0000 (20:02 +0000)
committerAndrei Zmievski <andrei@php.net>
Tue, 1 Feb 2000 20:02:44 +0000 (20:02 +0000)
  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)

TODO
ext/standard/file.c
ext/standard/file.h
ext/standard/fsock.c
ext/standard/fsock.h

diff --git a/TODO b/TODO
index c9ae5da16a4123759bb2363efa34ca9bb45fd6fa..f347724055e2b5b1f55a687f6769f3c1846ebe08 100644 (file)
--- a/TODO
+++ b/TODO
@@ -49,7 +49,6 @@ ext/standard
 ------------
     * 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 145c92589b06d61b18d3484d128881cd1d96c930..ba97256db8dc2ee1181205d3476d3d3f66ed15c3 100644 (file)
@@ -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;
        }
 
index e0e05cf98fb06fccbaa4bd15acc16ccb4b2c8f20..b05e98019244e820df22bad2320b4186ac14f7ec 100644 (file)
@@ -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);
index 0358e9e391ed8e5ce2c598a8951ec180c4bd4012..f13ed2d32369f0a37022d2430957ac7a68be9848 100644 (file)
@@ -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;
index 24bbef68109a0924033e56db43a306eef759e5b9..ff6c85d5b325178a58936934d01385a377b255f3 100644 (file)
 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);