Changeset: 5a9f96a5dca0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5a9f96a5dca0
Modified Files:
        tools/merovingian/daemon/multiplex-funnel.c
Branch: default
Log Message:

multiplex: properly null-terminate stream read buffer

In particular JDBC doesn't send newlines in requests, causing a buffer
to just end without, and no end of string marker.  This yields in the
severs seeing lots of old garbage, on which they complain.  Switch from
mnstr_read_block to mnstr_read, because the former doesn't properly set
the read length for some reason, which we need to properly terminate the
block read.  Ignore implicit flushes (reads of size 0) that the protocol
inserts on final blocks.

This allows to query using different queries (different sizes most
importantly), which helps clients that do a lot of meta-queries to
initialise and retrieve additional data.


diffs (45 lines):

diff --git a/tools/merovingian/daemon/multiplex-funnel.c 
b/tools/merovingian/daemon/multiplex-funnel.c
--- a/tools/merovingian/daemon/multiplex-funnel.c
+++ b/tools/merovingian/daemon/multiplex-funnel.c
@@ -507,12 +507,12 @@
        multiplex_client *c;
        int msock = -1;
        char buf[BLOCK + 1];
+       ssize_t len;
        int r, i;
 
        /* select on upstream clients, on new data, read query, forward,
         * union all results, send back, and restart cycle. */
        
-       buf[BLOCK] = '\0';
        while (_mero_keep_listening == 1) {
                FD_ZERO(&fds);
                for (c = m->clients; c != NULL; c = c->next) {
@@ -549,12 +549,17 @@
                for (c = m->clients; c != NULL; c = c->next) {
                        if (!FD_ISSET(c->sock, &fds))
                                continue;
-                       if (mnstr_read_block(c->fdin, buf, BLOCK, 1) < 0) {
+                       if ((len = mnstr_read(c->fdin, buf, 1, BLOCK)) < 0) {
                                /* error, or some garbage */
                                multiplexRemoveClient(m, c);
                                /* don't crash on now stale c */
                                break;
+                       } else if (len == 0) {
+                               /* flush from client, ignore */
+                               continue;
                        }
+
+                       buf[len] = '\0';
                        switch (*buf) {
                                case 's':
                                case 'S':
@@ -570,7 +575,7 @@
                                                        "multiplex-funnel\n", 
*buf);
                                        mnstr_flush(c->fout);
                                        Mfprintf(stderr, "client attempted to 
perform %c "
-                                                       "type query: %s", *buf, 
buf);
+                                                       "type query: %s\n", 
*buf, buf);
                                        continue;
                        }
                        /* we assume (and require) the query to fit in one 
block,
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to