]> granicus.if.org Git - php/commitdiff
A much better probable fix for #16114.
authorWez Furlong <wez@php.net>
Sun, 13 Oct 2002 23:43:21 +0000 (23:43 +0000)
committerWez Furlong <wez@php.net>
Sun, 13 Oct 2002 23:43:21 +0000 (23:43 +0000)
main/network.c
main/php_network.h

index 983d77b0ef941058746eef65e5c33fdd524fa67a..f973462b0888019817e89c14a44e743567231b3c 100644 (file)
@@ -849,6 +849,8 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS
 static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC)
 {
        php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
+       fd_set wrfds, efds;
+       int n;
 
        if (close_handle) {
 #if HAVE_OPENSSL_EXT
@@ -862,7 +864,18 @@ static int php_sockop_close(php_stream *stream, int close_handle TSRMLS_DC)
                }
 #endif
 
-               /* shutdown(sock->socket, 0); */
+               /* prevent more data from coming in */
+               shutdown(sock->socket, SHUT_RD);
+
+               /* make sure that the OS sends all data before we close the connection */
+               do {
+                       FD_ZERO(&wrfds);
+                       FD_SET(sock->socket, &wrfds);
+                       efds = wrfds;
+               
+                       n = select(sock->socket + 1, NULL, &wrfds, &efds, NULL);
+               } while (n == -1 && php_socket_errno() == EINTR);
+               
                closesocket(sock->socket);
 
        }
index 4e6ae61ad84d598408e5e8f0b5a8fed51387012e..05fcdead798d4e06038ec8d65b5a8352b8cb1f87 100644 (file)
@@ -27,6 +27,9 @@
 # undef FD_SETSIZE
 # include "arpa/inet.h"
 # define socklen_t unsigned int
+# define SHUT_RD       SD_RECEIVE
+# define SHUT_WR       SD_SEND
+# define SHUT_RDWR     SD_BOTH
 #else
 # undef closesocket
 # define closesocket close
@@ -62,6 +65,14 @@ PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize);
 #include <sys/socket.h>
 #endif
 
+/* These are here, rather than with the win32 counterparts above,
+ * since <sys/socket.h> defines them. */
+#ifndef SHUT_RD
+# define SHUT_RD 0
+# define SHUT_WR 1
+# define SHUT_RDWR 2
+#endif
+
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif