summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <msvensson@neptunus.(none)>2006-02-27 16:44:23 +0100
committerunknown <msvensson@neptunus.(none)>2006-02-27 16:44:23 +0100
commitf56e873418b1197525552b88b1d6a4d6b472543b (patch)
treeecca37e8c794c1b0031b82c402e26b01690ef5cb /sql
parentb97082c5836a48ff792183c555dcc3f41f0d5453 (diff)
downloadmariadb-git-f56e873418b1197525552b88b1d6a4d6b472543b.tar.gz
BUG#2845 client fails to reconnect if using TCP/IP
- Use 'poll' if available - Check that sd <= FD_SETSIZE if using 'select' - Handle case when 'net_data_is_ready' returns -1, ie. sd > FD_SETSIZE and 'select' is used sql/net_serv.cc: Use 'poll' in favor of 'select' if avaliable This is to avoid the limitation with 'select' only being able to handle fd's with numbers <= 1024 as default. If 'poll' is not available use 'select' but check that we are not having a number higher than FD_SETSIZE Handle the case when 'net_data_is_ready' can't check if there is data to read, since the sd number is too high
Diffstat (limited to 'sql')
-rw-r--r--sql/net_serv.cc29
1 files changed, 25 insertions, 4 deletions
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index ef56f0d77e2..b3ee28607ad 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -208,23 +208,40 @@ my_bool net_realloc(NET *net, ulong length)
RETURN VALUES
0 No data to read
1 Data or EOF to read
+ -1 Don't know if data is ready or not
*/
-static my_bool net_data_is_ready(my_socket sd)
+static int net_data_is_ready(my_socket sd)
{
+#ifdef HAVE_POLL
+ struct pollfd ufds;
+ int res;
+
+ ufds.fd= sd;
+ ufds.events= POLLIN | POLLPRI;
+ if (!(res= poll(&ufds, 1, 0)))
+ return 0;
+ if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)))
+ return 0;
+ return 1;
+#else
fd_set sfds;
struct timeval tv;
int res;
+ if (sd >= FD_SETSIZE)
+ return -1;
+
FD_ZERO(&sfds);
FD_SET(sd, &sfds);
tv.tv_sec= tv.tv_usec= 0;
if ((res= select(sd+1, &sfds, NULL, NULL, &tv)) < 0)
- return FALSE;
+ return 0;
else
return test(res ? FD_ISSET(sd, &sfds) : 0);
+#endif
}
@@ -251,10 +268,10 @@ static my_bool net_data_is_ready(my_socket sd)
void net_clear(NET *net)
{
- int count;
+ int count, ready;
DBUG_ENTER("net_clear");
#if !defined(EMBEDDED_LIBRARY)
- while(net_data_is_ready(net->vio->sd))
+ while((ready= net_data_is_ready(net->vio->sd)) != 0)
{
/* The socket is ready */
if ((count= vio_read(net->vio, (char*) (net->buff),
@@ -269,6 +286,10 @@ void net_clear(NET *net)
}
else
{
+ /* No data to read and 'net_data_is_ready' returned "don't know" */
+ if (ready == -1)
+ break;
+
DBUG_PRINT("info",("socket ready but only EOF to read - disconnected"));
net->error= 2;
break;