cvs: php4(PHP_4_3) /main network.c
| From: | Wez Furlong | Date: | Sat, 15 Feb 2003 15:11:57 +0000 |
| Subject: | cvs: php4(PHP_4_3) /main network.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-18841@lists.php.net to get a copy of this message | ||
wez Sat Feb 15 10:11:57 2003 EDT
Modified files: (Branch: PHP_4_3)
/php4/main network.c
Log:
MFH: Fix for Bug #21809 (select() never times out during socket shutdown)
Index: php4/main/network.c
diff -u php4/main/network.c:1.83.2.2 php4/main/network.c:1.83.2.3
--- php4/main/network.c:1.83.2.2 Tue Dec 31 11:26:11 2002
+++ php4/main/network.c Sat Feb 15 10:11:57 2003
@@ -16,7 +16,7 @@
| Streams work by Wez Furlong <wez@thebrainroom.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: network.c,v 1.83.2.2 2002/12/31 16:26:11 sebastian Exp $ */
+/* $Id: network.c,v 1.83.2.3 2003/02/15 15:11:57 wez Exp $ */
/*#define DEBUG_MAIN_NETWORK 1*/
@@ -599,6 +599,7 @@
sock->is_blocked = 1;
sock->timeout.tv_sec = FG(default_socket_timeout);
+ sock->timeout.tv_usec = 0;
sock->socket = socket;
stream = php_stream_alloc_rel(&php_stream_socket_ops, sock, persistent_id, "r+");
@@ -974,6 +975,7 @@
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
fd_set wrfds, efds;
int n;
+ struct timeval timeout;
if (close_handle) {
#if HAVE_OPENSSL_EXT
@@ -990,13 +992,21 @@
/* prevent more data from coming in */
shutdown(sock->socket, SHUT_RD);
- /* make sure that the OS sends all data before we close the connection */
+ /* try to make sure that the OS sends all data before we close the connection.
+ * Essentially, we are waiting for the socket to become writeable, which means
+ * that all pending data has been sent.
+ * We use a small timeout which should encourage the OS to send the data,
+ * but at the same time avoid hanging indefintely.
+ * */
do {
FD_ZERO(&wrfds);
FD_SET(sock->socket, &wrfds);
efds = wrfds;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 5000; /* arbitrary */
- n = select(sock->socket + 1, NULL, &wrfds, &efds, NULL);
+ n = select(sock->socket + 1, NULL, &wrfds, &efds, &timeout);
} while (n == -1 && php_socket_errno() == EINTR);
closesocket(sock->socket);