]> granicus.if.org Git - php/commitdiff
Probable fix for:
authorWez Furlong <wez@php.net>
Wed, 14 Jan 2004 14:54:14 +0000 (14:54 +0000)
committerWez Furlong <wez@php.net>
Wed, 14 Jan 2004 14:54:14 +0000 (14:54 +0000)
Bug #25575 stream_set_blocking with STDIN doesnt block

main/network.c

index 0b815ff3bbc6f7d2cc9a8c9e4d577a2574673271..5d9c2ae73a39210f5d3e81214cec82180fd609c5 100644 (file)
@@ -628,6 +628,22 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(int socket, const char *per
        memset(sock, 0, sizeof(php_netstream_data_t));
 
        sock->is_blocked = 1;
+
+#if !defined(PHP_WIN32) && (defined(O_NONBLOCK) || defined(O_NDELAY))
+       if (socket >= 0 && socket < 3) {
+               /* mini-hack: if we are opening stdin, stdout or stderr,
+                * we need to check to see if they are currently in
+                * blocking or non-blocking mode. */
+               int flags = fcntl(socket, F_GETFL);
+
+#ifdef O_NONBLOCK
+               sock->is_blocked = !(flags & O_NONBLOCK);
+#else
+               sock->is_blocked = !(flags & O_NDELAY);
+#endif
+       }
+#endif
+       
        sock->timeout.tv_sec = FG(default_socket_timeout);
        sock->timeout.tv_usec = 0;
        sock->socket = socket;