dmitry          Tue Dec 19 08:58:59 2006 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/standard/tests/network shutdown.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/main/streams       php_stream_transport.h transports.c 
                                xp_socket.c 
    /php-src/ext/standard       basic_functions.c file.c streamsfuncs.c 
                                streamsfuncs.h 
  Log:
  Added function stream_socket_shutdown(). It is a wraper for system shutdown() 
function, that shut downs part of a full-duplex connection
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.440&r2=1.2027.2.547.2.441&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.440 php-src/NEWS:1.2027.2.547.2.441
--- php-src/NEWS:1.2027.2.547.2.440     Tue Dec 19 08:18:47 2006
+++ php-src/NEWS        Tue Dec 19 08:58:58 2006
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Dec 2006, PHP 5.2.1RC2
+- Added function stream_socket_shutdown(). It is a wraper for system shutdown()
+  function, that shut downs part of a full-duplex connection. (Dmitry)
 - Added internal heap protection (Dmitry)
   . safe unlinking
   . cookies
http://cvs.php.net/viewvc.cgi/php-src/main/streams/php_stream_transport.h?r1=1.10.2.1&r2=1.10.2.1.2.1&diff_format=u
Index: php-src/main/streams/php_stream_transport.h
diff -u php-src/main/streams/php_stream_transport.h:1.10.2.1 
php-src/main/streams/php_stream_transport.h:1.10.2.1.2.1
--- php-src/main/streams/php_stream_transport.h:1.10.2.1        Sun Jan  1 
12:50:18 2006
+++ php-src/main/streams/php_stream_transport.h Tue Dec 19 08:58:58 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_stream_transport.h,v 1.10.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: php_stream_transport.h,v 1.10.2.1.2.1 2006/12/19 08:58:58 dmitry Exp $ 
*/
 
 #if HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
@@ -104,8 +104,19 @@
  * sending it as OOB data */
 PHPAPI int php_stream_xport_sendto(php_stream *stream, const char *buf, size_t 
buflen,
                long flags, void *addr, socklen_t addrlen TSRMLS_DC);
+
+typedef enum {
+       STREAM_SHUT_RD,
+       STREAM_SHUT_WR,
+       STREAM_SHUT_RDWR
+} stream_shutdown_t;
+
+/* Similar to shutdown() system call; shut down part of a full-duplex
+ * connection */
+PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how 
TSRMLS_DC);
 END_EXTERN_C()
 
+
 /* Structure definition for the set_option interface that the above functions 
wrap */
 
 typedef struct _php_stream_xport_param {
@@ -116,11 +127,13 @@
                STREAM_XPORT_OP_GET_NAME,
                STREAM_XPORT_OP_GET_PEER_NAME,
                STREAM_XPORT_OP_RECV,
-               STREAM_XPORT_OP_SEND
+               STREAM_XPORT_OP_SEND,
+               STREAM_XPORT_OP_SHUTDOWN
        } op;
        unsigned int want_addr:1;
        unsigned int want_textaddr:1;
        unsigned int want_errortext:1;
+       stream_shutdown_t how:3;
 
        struct {
                char *name;
http://cvs.php.net/viewvc.cgi/php-src/main/streams/transports.c?r1=1.16.2.1&r2=1.16.2.1.2.1&diff_format=u
Index: php-src/main/streams/transports.c
diff -u php-src/main/streams/transports.c:1.16.2.1 
php-src/main/streams/transports.c:1.16.2.1.2.1
--- php-src/main/streams/transports.c:1.16.2.1  Sun Jan  1 12:50:18 2006
+++ php-src/main/streams/transports.c   Tue Dec 19 08:58:58 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: transports.c,v 1.16.2.1 2006/01/01 12:50:18 sniper Exp $ */
+/* $Id: transports.c,v 1.16.2.1.2.1 2006/12/19 08:58:58 dmitry Exp $ */
 
 #include "php.h"
 #include "php_streams_int.h"
@@ -486,6 +486,25 @@
        return -1;
 }
 
+/* Similar to shutdown() system call; shut down part of a full-duplex
+ * connection */
+PHPAPI int php_stream_xport_shutdown(php_stream *stream, stream_shutdown_t how 
TSRMLS_DC)
+{
+       php_stream_xport_param param;
+       int ret = 0;
+
+       memset(&param, 0, sizeof(param));
+
+       param.op = STREAM_XPORT_OP_SHUTDOWN;
+       param.how = how;
+       
+       ret = php_stream_set_option(stream, PHP_STREAM_OPTION_XPORT_API, 0, 
&param);
+
+       if (ret == PHP_STREAM_OPTION_RETURN_OK) {
+               return param.outputs.returncode;
+       }
+       return -1;
+}
 
 /*
  * Local variables:
http://cvs.php.net/viewvc.cgi/php-src/main/streams/xp_socket.c?r1=1.33.2.2.2.1&r2=1.33.2.2.2.2&diff_format=u
Index: php-src/main/streams/xp_socket.c
diff -u php-src/main/streams/xp_socket.c:1.33.2.2.2.1 
php-src/main/streams/xp_socket.c:1.33.2.2.2.2
--- php-src/main/streams/xp_socket.c:1.33.2.2.2.1       Wed Oct 11 12:53:56 2006
+++ php-src/main/streams/xp_socket.c    Tue Dec 19 08:58:58 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: xp_socket.c,v 1.33.2.2.2.1 2006/10/11 12:53:56 tony2001 Exp $ */
+/* $Id: xp_socket.c,v 1.33.2.2.2.2 2006/12/19 08:58:58 dmitry Exp $ */
 
 #include "php.h"
 #include "ext/standard/file.h"
@@ -369,6 +369,24 @@
                                        return PHP_STREAM_OPTION_RETURN_OK;
 
 
+#ifdef HAVE_SHUTDOWN
+# ifndef SHUT_RD
+#  define SHUT_RD 0
+# endif
+# ifndef SHUT_WR
+#  define SHUT_WR 1
+# endif
+# ifndef SHUT_RDWR
+#  define SHUT_RDWR 2
+# endif
+                               case STREAM_XPORT_OP_SHUTDOWN: {
+                                       static const int shutdown_how[] = 
{SHUT_RD, SHUT_WR, SHUT_RDWR};
+
+                                       xparam->outputs.returncode = 
shutdown(sock->socket, shutdown_how[xparam->how]);
+                                       return PHP_STREAM_OPTION_RETURN_OK;
+                               }
+#endif
+                               
                                default:
                                        return PHP_STREAM_OPTION_RETURN_NOTIMPL;
                        }
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.35&r2=1.725.2.31.2.36&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.35 
php-src/ext/standard/basic_functions.c:1.725.2.31.2.36
--- php-src/ext/standard/basic_functions.c:1.725.2.31.2.35      Wed Dec 13 
15:31:47 2006
+++ php-src/ext/standard/basic_functions.c      Tue Dec 19 08:58:58 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.725.2.31.2.35 2006/12/13 15:31:47 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.725.2.31.2.36 2006/12/19 08:58:58 dmitry Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -2443,6 +2443,14 @@
        ZEND_ARG_INFO(0, cryptokind)
        ZEND_ARG_INFO(0, sessionstream)
 ZEND_END_ARG_INFO()
+
+#ifdef HAVE_SHUTDOWN
+static
+ZEND_BEGIN_ARG_INFO(arginfo_stream_socket_shutdown, 0)
+       ZEND_ARG_INFO(0, stream)
+       ZEND_ARG_INFO(0, how)
+ZEND_END_ARG_INFO()
+#endif
 /* }}} */
 /* {{{ string.c */
 static
@@ -3517,6 +3525,9 @@
        PHP_FE(stream_socket_recvfrom,                                          
                                        arginfo_stream_socket_recvfrom)
        PHP_FE(stream_socket_sendto,                                            
                                        arginfo_stream_socket_sendto)
        PHP_FE(stream_socket_enable_crypto,                                     
                                        arginfo_stream_socket_enable_crypto)
+#ifdef HAVE_SHUTDOWN
+       PHP_FE(stream_socket_shutdown,                                          
                                        arginfo_stream_socket_shutdown)
+#endif
 #if HAVE_SOCKETPAIR
        PHP_FE(stream_socket_pair,                                              
                                                arginfo_stream_socket_pair)
 #endif
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.13&r2=1.409.2.6.2.14&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.13 
php-src/ext/standard/file.c:1.409.2.6.2.14
--- php-src/ext/standard/file.c:1.409.2.6.2.13  Sat Dec  9 18:00:52 2006
+++ php-src/ext/standard/file.c Tue Dec 19 08:58:58 2006
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.409.2.6.2.13 2006/12/09 18:00:52 bjori Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.14 2006/12/19 08:58:58 dmitry Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -228,6 +228,10 @@
        REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv23_SERVER",    
STREAM_CRYPTO_METHOD_SSLv23_SERVER,     CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLS_SERVER",               
STREAM_CRYPTO_METHOD_TLS_SERVER,        CONST_CS|CONST_PERSISTENT);
        
+       REGISTER_LONG_CONSTANT("STREAM_SHUT_RD",        STREAM_SHUT_RD,         
CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("STREAM_SHUT_WR",        STREAM_SHUT_WR,         
CONST_CS|CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("STREAM_SHUT_RDWR",      STREAM_SHUT_RDWR,       
CONST_CS|CONST_PERSISTENT);
+
 #ifdef PF_INET
        REGISTER_LONG_CONSTANT("STREAM_PF_INET", PF_INET, 
CONST_CS|CONST_PERSISTENT);
 #elif defined(AF_INET)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.58.2.6.2.9&r2=1.58.2.6.2.10&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.9 
php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.10
--- php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.9    Wed Oct 11 23:22:45 2006
+++ php-src/ext/standard/streamsfuncs.c Tue Dec 19 08:58:58 2006
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.c,v 1.58.2.6.2.9 2006/10/11 23:22:45 pollita Exp $ */
+/* $Id: streamsfuncs.c,v 1.58.2.6.2.10 2006/12/19 08:58:58 dmitry Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -1341,6 +1341,36 @@
 }
 /* }}} */
 
+#ifdef HAVE_SHUTDOWN
+/* {{{ proto int stream_socket_shutdown(resource stream, int how)
+       causes all or part of a full-duplex connection on the socket associated
+       with stream to be shut down.  If how is SHUT_RD,  further receptions 
will
+       be disallowed. If how is SHUT_WR, further transmissions will be 
disallowed.
+       If how is SHUT_RDWR,  further  receptions and transmissions will be
+       disallowed. */
+PHP_FUNCTION(stream_socket_shutdown)
+{
+       long how;
+       zval *zstream;
+       php_stream *stream;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zstream, 
&how) == FAILURE) {
+               RETURN_FALSE;
+       }
+       
+       if (how != STREAM_SHUT_RD &&
+           how != STREAM_SHUT_WR &&
+           how != STREAM_SHUT_RDWR) {
+               RETURN_FALSE;
+       }
+
+       php_stream_from_zval(stream, &zstream);
+
+       RETURN_BOOL(php_stream_xport_shutdown(stream, (stream_shutdown_t)how 
TSRMLS_CC) == 0);
+}
+#endif
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.h?r1=1.13.2.1.2.1&r2=1.13.2.1.2.2&diff_format=u
Index: php-src/ext/standard/streamsfuncs.h
diff -u php-src/ext/standard/streamsfuncs.h:1.13.2.1.2.1 
php-src/ext/standard/streamsfuncs.h:1.13.2.1.2.2
--- php-src/ext/standard/streamsfuncs.h:1.13.2.1.2.1    Mon Jun 26 16:33:39 2006
+++ php-src/ext/standard/streamsfuncs.h Tue Dec 19 08:58:58 2006
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.h,v 1.13.2.1.2.1 2006/06/26 16:33:39 bjori Exp $ */
+/* $Id: streamsfuncs.h,v 1.13.2.1.2.2 2006/12/19 08:58:58 dmitry Exp $ */
 
 /* Flags for stream_socket_client */
 #define PHP_STREAM_CLIENT_PERSISTENT   1
@@ -53,6 +53,7 @@
 PHP_FUNCTION(stream_filter_append);
 PHP_FUNCTION(stream_filter_remove);
 PHP_FUNCTION(stream_socket_enable_crypto);
+PHP_FUNCTION(stream_socket_shutdown);
 PHP_FUNCTION(stream_socket_pair);
 
 /*

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/shutdown.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/network/shutdown.phpt
+++ php-src/ext/standard/tests/network/shutdown.phpt

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to