Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory
23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv2429/src/backends/monet5/merovingian
Modified Files:
merovingian_controlrunner.c
Log Message:
propagated changes of Thursday Oct 01 2009 - Friday Oct 02 2009
from the Nov2009 branch to the development trunk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/10/01 - mr-meltdown:
src/backends/monet5/merovingian/merovingian_controlrunner.c,1.26.2.4
protect ourself from clients that connect but never tell us what they want
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: merovingian_controlrunner.c
===================================================================
RCS file:
/cvsroot/monetdb/sql/src/backends/monet5/merovingian/merovingian_controlrunner.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- merovingian_controlrunner.c 1 Oct 2009 14:25:04 -0000 1.28
+++ merovingian_controlrunner.c 2 Oct 2009 07:31:03 -0000 1.29
@@ -61,6 +61,28 @@
GDKfree(props);
}
+inline static int
+recvWithTimeout(int msgsock, char *buf, size_t buflen)
+{
+ fd_set fds;
+ struct timeval tv;
+ int retval;
+
+ FD_ZERO(&fds);
+ FD_SET(msgsock, &fds);
+
+ /* Wait up to 1 second. If a client doesn't make this, it's too slow */
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ retval = select(msgsock + 1, &fds, NULL, NULL, &tv);
+ if (retval == 0) {
+ /* nothing interesting has happened */
+ return(-2);
+ }
+
+ return(recv(msgsock, buf, buflen, 0));
+}
+
static void
controlRunner(void *d)
{
@@ -175,7 +197,7 @@
len = snprintf(buf2, sizeof(buf2),
"merovingian:1:%s:\n", p);
send(msgsock, buf2, len, 0);
- if ((pos = recv(msgsock, buf2, sizeof(buf2), 0)) == 0) {
+ if ((pos = recvWithTimeout(msgsock, buf2,
sizeof(buf2))) == 0) {
close(msgsock);
continue;
} else if (pos == -1) {
@@ -183,6 +205,11 @@
"channel: %s\n", origin,
strerror(errno));
close(msgsock);
continue;
+ } else if (pos == -2) {
+ Mfprintf(_mero_ctlerr, "%s: time-out reading
from control "
+ "channel, disconnecting
client\n", origin);
+ close(msgsock);
+ continue;
}
buf2[pos - 1] = '\0';
pos = 0;
@@ -203,7 +230,7 @@
while (_mero_keep_listening) {
if (pos == 0) {
- if ((pos = recv(msgsock, buf, sizeof(buf), 0))
== 0) {
+ if ((pos = recvWithTimeout(msgsock, buf,
sizeof(buf))) == 0) {
/* EOF */
break;
} else if (pos == -1) {
@@ -216,6 +243,11 @@
Mfprintf(_mero_ctlerr, "%s: error
reading from control "
"channel: %s\n",
origin, strerror(errno));
break;
+ } else if (pos == -2) {
+ Mfprintf(_mero_ctlerr, "%s: time-out
reading from "
+ "control channel,
disconnecting client\n", origin);
+ close(msgsock);
+ break;
} else {
buf[pos] = '\0';
pos = 0;
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins