cvs: php4(PHP_4_3) /ext/standard fsock.c /main network.c php_network.h
| From: | Wez Furlong | Date: | Mon, 12 May 2003 23:44:49 +0000 |
| Subject: | cvs: php4(PHP_4_3) /ext/standard fsock.c /main network.c php_network.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20847@lists.php.net to get a copy of this message | ||
wez Mon May 12 19:44:49 2003 EDT
Modified files: (Branch: PHP_4_3)
/php4/ext/standard fsock.c
/php4/main network.c php_network.h
Log:
Probable fix for #23567 - pfsockopen returns dead connection.
# Just need to verify under win32
Index: php4/ext/standard/fsock.c
diff -u php4/ext/standard/fsock.c:1.106.2.4 php4/ext/standard/fsock.c:1.106.2.5
--- php4/ext/standard/fsock.c:1.106.2.4 Sat Apr 26 17:34:48 2003
+++ php4/ext/standard/fsock.c Mon May 12 19:44:48 2003
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: fsock.c,v 1.106.2.4 2003/04/26 21:34:48 wez Exp $ */
+/* $Id: fsock.c,v 1.106.2.5 2003/05/12 23:44:48 wez Exp $ */
/* converted to PHP Streams and moved much code to main/network.c [wez] */
@@ -160,8 +160,13 @@
switch(php_stream_from_persistent_id(hashkey, &stream TSRMLS_CC)) {
case PHP_STREAM_PERSISTENT_SUCCESS:
- /* TODO: could check if the socket is still alive here */
- php_stream_to_zval(stream, return_value);
+ if (_php_network_is_stream_alive(stream)) {
+ php_stream_to_zval(stream, return_value);
+ } else {
+ /* it died; we need to replace it */
+ php_stream_close(stream);
+ break;
+ }
/* fall through */
case PHP_STREAM_PERSISTENT_FAILURE:
Index: php4/main/network.c
diff -u php4/main/network.c:1.83.2.8 php4/main/network.c:1.83.2.9
--- php4/main/network.c:1.83.2.8 Mon May 12 00:05:54 2003
+++ php4/main/network.c Mon May 12 19:44:48 2003
@@ -16,7 +16,7 @@
| Streams work by Wez Furlong <wez@thebrainroom.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: network.c,v 1.83.2.8 2003/05/12 04:05:54 iliaa Exp $ */
+/* $Id: network.c,v 1.83.2.9 2003/05/12 23:44:48 wez Exp $ */
/*#define DEBUG_MAIN_NETWORK 1*/
@@ -1100,6 +1100,35 @@
return PHP_STREAM_OPTION_RETURN_NOTIMPL;
}
}
+
+/* private API; don't use in extensions */
+int _php_network_is_stream_alive(php_stream *stream)
+{
+ php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
+ int alive = 1;
+ int fd = sock->socket;
+ fd_set rfds;
+ struct timeval tv = {0, 0};
+ char buf;
+
+ /* logic: if the select call indicates that there is data to
+ * be read, but a read returns 0 bytes of data, then the socket
+ * has been closed.
+ */
+
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+ if (select(fd+1, &rfds, NULL, NULL, &tv) > 0) {
+
+ if (FD_ISSET(fd, &rfds)) {
+ if (0 == recv(fd, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EAGAIN) {
+ alive = 0;
+ }
+ }
+ }
+ return alive;
+}
+
static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
{
Index: php4/main/php_network.h
diff -u php4/main/php_network.h:1.37.2.1 php4/main/php_network.h:1.37.2.2
--- php4/main/php_network.h:1.37.2.1 Tue Dec 31 11:26:18 2002
+++ php4/main/php_network.h Mon May 12 19:44:48 2003
@@ -15,7 +15,7 @@
| Author: Stig Venaas <venaas@uninett.no> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_network.h,v 1.37.2.1 2002/12/31 16:26:18 sebastian Exp $ */
+/* $Id: php_network.h,v 1.37.2.2 2003/05/12 23:44:48 wez Exp $ */
#ifndef _PHP_NETWORK_H
#define _PHP_NETWORK_H
@@ -154,6 +154,9 @@
#define php_stream_sock_open_unix_rel(path, pathlen, persistent,
timeval) _php_stream_sock_open_unix((path), (pathlen), (persistent), (timeval) STREAMS_REL_CC
TSRMLS_CC)
/* }}} */
+
+/* private API; don't use in extensions */
+int _php_network_is_stream_alive(php_stream *stream);
#if HAVE_OPENSSL_EXT
PHPAPI int php_stream_sock_ssl_activate_with_method(php_stream *stream, int activate, SSL_METHOD
*method, php_stream *session_stream TSRMLS_DC);