Changeset: ec34b32c2874 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec34b32c2874
Modified Files:
        clients/mapiclient/stethoscope.c
        clients/mapiclient/tachograph.c
        clients/mapiclient/tomograph.c
Branch: default
Log Message:

more fixes related to handling very long queries

- fix string index
- extend 'len' for incomplete lines
- don't treat incomplete line as LASTLINE


diffs (132 lines):

diff --git a/clients/mapiclient/stethoscope.c b/clients/mapiclient/stethoscope.c
--- a/clients/mapiclient/stethoscope.c
+++ b/clients/mapiclient/stethoscope.c
@@ -274,7 +274,7 @@ main(int argc, char **argv)
                fprintf(stderr,"Could not create input buffer\n");
                exit(-1);
        }
-       while ((n = mnstr_read(conn, buffer + len, 1, buflen - len)) > 0) {
+       while ((n = mnstr_read(conn, buffer + len, 1, buflen - len -1)) > 0) {
                buffer[len + n] = 0;
                if( trace) 
                        fprintf(trace,"%s",buffer);
@@ -287,7 +287,8 @@ main(int argc, char **argv)
                        }
                        response = e + 1;
                }
-               /* handle the case that the line is not yet completed */
+               /* handle the case that the current line is too long to
+                * fit in the buffer */
                if( response == buffer){
                        char *new =  (char *) realloc(buffer, buflen + BUFSIZ);
                        if( new == NULL){
@@ -296,14 +297,18 @@ main(int argc, char **argv)
                        }
                        buffer = new;
                        buflen += BUFSIZ;
+                       len += n;
                }
-               /* handle last line in buffer */
-               if (*response) {
+               /* handle the case the buffer contains more than one
+                * line, and the last line is not completely read yet.
+                * Copy the first part of the incomplete line to the
+                * beginning of the buffer */
+               else if (*response) {
                        if (debug)
                                printf("LASTLINE:%s", response);
                        len = strlen(response);
                        strncpy(buffer, response, len + 1);
-               } else
+               } else /* reset this line of buffer */
                        len = 0;
        }
 
diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c
--- a/clients/mapiclient/tachograph.c
+++ b/clients/mapiclient/tachograph.c
@@ -1025,7 +1025,7 @@ main(int argc, char **argv)
                fprintf(stderr,"Could not create input buffer\n");
                exit(-1);
        }
-       while ((n = mnstr_read(conn, buffer + len, 1, buflen - len)) > 0) {
+       while ((n = mnstr_read(conn, buffer + len, 1, buflen - len -1)) > 0) {
                buffer[len + n] = 0;
                response = buffer;
                while ((e = strchr(response, '\n')) != NULL) {
@@ -1042,7 +1042,8 @@ main(int argc, char **argv)
                                fprintf(tachotrace,"%s\n",response);
                        response = e + 1;
                }
-               /* handle the case that the line is not yet completed */
+               /* handle the case that the current line is too long to
+                * fit in the buffer */
                if( response == buffer){
                        char *new =  (char *) realloc(buffer, buflen + BUFSIZ);
                        if( new == NULL){
@@ -1051,14 +1052,18 @@ main(int argc, char **argv)
                        }
                        buffer = new;
                        buflen += BUFSIZ;
+                       len += n;
                }
-               /* handle last part of line in buffer */
-               if (response != buffer && *response) {
+               /* handle the case the buffer contains more than one
+                * line, and the last line is not completely read yet.
+                * Copy the first part of the incomplete line to the
+                * beginning of the buffer */
+               else if (*response) {
                        if (debug)
                                printf("LASTLINE:%s", response);
                        len = strlen(response);
                        strncpy(buffer, response, len + 1);
-               } else
+               } else /* reset this line of buffer */
                        len = 0;
        }
 
diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c
--- a/clients/mapiclient/tomograph.c
+++ b/clients/mapiclient/tomograph.c
@@ -1904,7 +1904,7 @@ main(int argc, char **argv)
                        exit(-1);
                }
                resetTomograph();
-               while ((m = mnstr_read(conn, buffer + len, 1, buflen - len)) > 
0) {
+               while ((m = mnstr_read(conn, buffer + len, 1, buflen - len - 
1)) > 0) {
                        buffer[len + m] = 0;
                        response = buffer;
                        while ((e = strchr(response, '\n')) != NULL) {
@@ -1915,7 +1915,8 @@ main(int argc, char **argv)
                                        fprintf(stderr, "PARSE %d:%s\n", i, 
response);
                                response = e + 1;
                        }
-                       /* handle the case that the line is not yet completed */
+                       /* handle the case that the current line is too long to
+                        * fit in the buffer */
                        if( response == buffer){
                                char *new = realloc(buffer, buflen + BUFSIZ);
                                if( new == NULL){
@@ -1924,14 +1925,18 @@ main(int argc, char **argv)
                                }
                                buffer = new;
                                buflen += BUFSIZ;
+                               len += m;
                        }
-                       /* handle last line in buffer */
-                       if (response != buffer && *response) {
+                       /* handle the case the buffer contains more than one
+                         * line, and the last line is not completely read yet.
+                        * Copy the first part of the incomplete line to the
+                        * beginning of the buffer */
+                       else if (*response) {
                                if (debug)
                                        fprintf(stderr,"LASTLINE:%s", response);
                                len = strlen(response);
                                strncpy(buffer, response, len + 1);
-                       } else
+                       } else /* reset this line of buffer */
                                len = 0;
                }
        }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to