~ignacio-nin/percona-server/5.1-issue26684

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# name       : bugfix48929.patch
# introduced : 11 or before
# maintainer : Oleg
#
#!!! notice !!!
# Any small change to this file in the main branch
# should be done or reviewed by the maintainer!
diff -ruN a/configure.in b/configure.in
--- a/configure.in	2010-07-07 03:33:05.008972002 +0400
+++ b/configure.in	2010-07-07 03:33:05.788972002 +0400
@@ -815,7 +815,7 @@
 AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS(fcntl.h fenv.h float.h floatingpoint.h fpu_control.h \
- ieeefp.h limits.h memory.h pwd.h select.h \
+ ieeefp.h limits.h memory.h pwd.h select.h poll.h \
  stdlib.h stddef.h \
  strings.h string.h synch.h sys/mman.h sys/socket.h netinet/in.h arpa/inet.h \
  sys/timeb.h sys/types.h sys/un.h sys/vadvise.h sys/wait.h term.h \
diff -ruN a/configure b/configure
--- a/configure	2010-07-26 18:29:12.172114128 +0900
+++ b/configure	2010-07-26 20:44:59.199030524 +0900
@@ -21527,7 +21527,7 @@
 
 
 for ac_header in fcntl.h fenv.h float.h floatingpoint.h fpu_control.h \
- ieeefp.h limits.h memory.h pwd.h select.h \
+ ieeefp.h limits.h memory.h pwd.h select.h poll.h \
  stdlib.h stddef.h \
  strings.h string.h synch.h sys/mman.h sys/socket.h netinet/in.h arpa/inet.h \
  sys/timeb.h sys/types.h sys/un.h sys/vadvise.h sys/wait.h term.h \
diff -ruN a/include/config.h.in b/include/config.h.in
--- a/include/config.h.in	2010-07-26 18:29:12.192113524 +0900
+++ b/include/config.h.in	2010-07-26 20:46:08.265182869 +0900
@@ -609,6 +609,9 @@
 /* Define to 1 if you have the `poll' function. */
 #undef HAVE_POLL
 
+/* Define to 1 if you have the <poll.h> header file. */
+#undef HAVE_POLL_H
+
 /* Define to 1 if you have the `port_create' function. */
 #undef HAVE_PORT_CREATE
 
diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2010-07-07 03:33:05.278972002 +0400
+++ b/sql/mysqld.cc	2010-07-07 03:33:05.788972002 +0400
@@ -55,6 +55,10 @@
 #include "sp_rcontext.h"
 #include "sp_cache.h"
 
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
+
 #define mysqld_charset &my_charset_latin1
 
 #ifdef HAVE_purify
@@ -5118,28 +5122,49 @@
 {
   my_socket sock,new_sock;
   uint error_count=0;
-  uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
-  fd_set readFDs,clientFDs;
   THD *thd;
   struct sockaddr_in cAddr;
-  int ip_flags=0,socket_flags=0,flags;
+  int ip_flags=0,socket_flags=0,flags,retval;
   st_vio *vio_tmp;
+#ifdef HAVE_POLL
+  int socket_count= 0;
+  struct pollfd fds[2]; // for ip_sock and unix_sock
+#else
+  fd_set readFDs,clientFDs;
+  uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
+#endif
+
   DBUG_ENTER("handle_connections_sockets");
 
   LINT_INIT(new_sock);
 
   (void) my_pthread_getprio(pthread_self());		// For debugging
 
+#ifndef HAVE_POLL
   FD_ZERO(&clientFDs);
+#endif
+
   if (ip_sock != INVALID_SOCKET)
   {
+#ifdef HAVE_POLL
+    fds[socket_count].fd= ip_sock;
+    fds[socket_count].events= POLLIN;
+    socket_count++;
+#else
     FD_SET(ip_sock,&clientFDs);
+#endif
 #ifdef HAVE_FCNTL
     ip_flags = fcntl(ip_sock, F_GETFL, 0);
 #endif
   }
 #ifdef HAVE_SYS_UN_H
+#ifdef HAVE_POLL
+  fds[socket_count].fd= unix_sock;
+  fds[socket_count].events= POLLIN;
+  socket_count++;
+#else
   FD_SET(unix_sock,&clientFDs);
+#endif
 #ifdef HAVE_FCNTL
   socket_flags=fcntl(unix_sock, F_GETFL, 0);
 #endif
@@ -5149,12 +5174,15 @@
   MAYBE_BROKEN_SYSCALL;
   while (!abort_loop)
   {
-    readFDs=clientFDs;
-#ifdef HPUX10
-    if (select(max_used_connection,(int*) &readFDs,0,0,0) < 0)
-      continue;
+#ifdef HAVE_POLL
+    retval= poll(fds, socket_count, -1);
 #else
-    if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
+    readFDs=clientFDs;
+
+    retval= select((int) max_used_connection,&readFDs,0,0,0);
+#endif
+
+    if (retval < 0)
     {
       if (socket_errno != SOCKET_EINTR)
       {
@@ -5164,7 +5192,7 @@
       MAYBE_BROKEN_SYSCALL
       continue;
     }
-#endif	/* HPUX10 */
+
     if (abort_loop)
     {
       MAYBE_BROKEN_SYSCALL;
@@ -5172,6 +5200,21 @@
     }
 
     /* Is this a new connection request ? */
+#ifdef HAVE_POLL
+    for (int i= 0; i < socket_count; ++i) 
+    {
+      if (fds[i].revents & POLLIN)
+      {
+        sock= fds[i].fd;
+#ifdef HAVE_FCNTL
+        flags= fcntl(sock, F_GETFL, 0);
+#else
+        flags= 0;
+#endif // HAVE_FCNTL
+        break;
+      }
+    }
+#else  // HAVE_POLL
 #ifdef HAVE_SYS_UN_H
     if (FD_ISSET(unix_sock,&readFDs))
     {
@@ -5179,11 +5222,12 @@
       flags= socket_flags;
     }
     else
-#endif
+#endif // HAVE_SYS_UN_H
     {
       sock = ip_sock;
       flags= ip_flags;
     }
+#endif // HAVE_POOL
 
 #if !defined(NO_FCNTL_NONBLOCK)
     if (!(test_flags & TEST_BLOCKING))