summaryrefslogtreecommitdiffstats
path: root/php-5.4.11-select.patch
blob: 3c2a9a3865cd1289c983eb55cdf56eb35a8ac78f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 0cea9e6843384c6c0ebb52047c42b0431a4f5660 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Fri, 1 Feb 2013 19:23:25 +0100
Subject: [PATCH] Fixed bug #64128 buit-in web server is broken on ppc64.

fdset management using bit operator is broken on non-x86 arch
and cause built-in server the enter an infinite loop of "select"
and never handle any request.
---
 NEWS                      |  3 +++
 sapi/cli/php_cli_server.c | 30 +++++++++++++-----------------
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index 28aba19..6a4e7c5 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -710,10 +710,9 @@ static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode
 	if (fd == poller->max_fd) {
 		while (fd > 0) {
 			fd--;
-			if (((unsigned int *)&poller->rfds)[fd / (8 * sizeof(unsigned int))] || ((unsigned int *)&poller->wfds)[fd / (8 * sizeof(unsigned int))]) {
+			if (PHP_SAFE_FD_ISSET(fd, &poller->rfds) || PHP_SAFE_FD_ISSET(fd, &poller->wfds)) {
 				break;
 			}
-			fd -= fd % (8 * sizeof(unsigned int));
 		}
 		poller->max_fd = fd;
 	}
@@ -772,23 +771,20 @@ static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, v
 	}
 
 #else
-	php_socket_t fd = 0;
+	php_socket_t fd;
 	const php_socket_t max_fd = poller->max_fd;
-	const unsigned int *pr = (unsigned int *)&poller->active.rfds,
-	                   *pw = (unsigned int *)&poller->active.wfds,
-	                   *e = pr + (max_fd + (8 * sizeof(unsigned int)) - 1) / (8 * sizeof(unsigned int));
-	unsigned int mask;
-	while (pr < e && fd <= max_fd) {
-		for (mask = 1; mask; mask <<= 1, fd++) {
-			int events = (*pr & mask ? POLLIN: 0) | (*pw & mask ? POLLOUT: 0);
-			if (events) {
-				if (SUCCESS != callback(opaque, fd, events)) {
-					retval = FAILURE;
-				}
-			}
+
+	for (fd=0 ; fd<=max_fd ; fd++)  {
+		if (PHP_SAFE_FD_ISSET(fd, &poller->active.rfds)) {
+                if (SUCCESS != callback(opaque, fd, POLLIN)) {
+                    retval = FAILURE;
+                }
+		}
+		if (PHP_SAFE_FD_ISSET(fd, &poller->active.wfds)) {
+                if (SUCCESS != callback(opaque, fd, POLLOUT)) {
+                    retval = FAILURE;
+                }
 		}
-		pr++;
-		pw++;
 	}
 #endif
 	return retval;
-- 
1.7.11.5