Thread: [Refdb-cvs] CVS: refdb/src refdbc.c,1.72.2.2,1.72.2.3
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2004-12-10 13:19:18
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8614 Modified Files: Tag: Release_0_9_5_stable refdbc.c Log Message: addref and addnote now read phase 5 server message in loop to avoid truncated messages Index: refdbc.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdbc.c,v retrieving revision 1.72.2.2 retrieving revision 1.72.2.3 diff -u -U2 -r1.72.2.2 -r1.72.2.3 --- refdbc.c 27 Nov 2004 23:15:39 -0000 1.72.2.2 +++ refdbc.c 10 Dec 2004 13:19:08 -0000 1.72.2.3 @@ -65,4 +65,6 @@ #include "cgi.h" /* cgi related stuff */ +extern const char cs_term[]; + /*+ the commands array contains the user commands, the functions called, and short explanatory messages +*/ @@ -2798,4 +2800,6 @@ int n_keep_id = 0; /* indicates -k switch */ int n_send_result; + int n_curr_trailing_z = 0; + int n_last_trailing_z = 0; int i, j, k; /* guess what */ size_t byte_written = 0; @@ -3294,43 +3298,98 @@ return 1; } - - numbyte = tread(n_sockfd, inbuffer, COMMAND_INBUF_LEN); - - if (numbyte == -1) { - cgi_header(CGI_PLAIN); - fprintf(errstream, "could not read from refdbd. Stop\n"); - if (n_file_open || n_file_append) { - close_outfile(pagerfp); - } - else { - closepager(pagerfp); + + /* must read in loop */ + do { + numbyte = tread(n_sockfd, inbuffer, OUTBUF_LEN); + if (numbyte == -1) { + fprintf(stderr, "could not read from refdbd. Stop\n"); + if (n_file_open || n_file_append) { + close_outfile(pagerfp); + } + else { + closepager(pagerfp); + } + n_broken_pipe = 0; + return 1; } - delete_all_lilimem(&sentinel); - close(n_sockfd); - n_broken_pipe = 0; - return 1; - } - if (!*inbuffer) { - cgi_header(CGI_PLAIN); - fprintf(errstream, "server error. Stop.\n"); - if (n_file_open || n_file_append) { - close_outfile(pagerfp); + n_curr_trailing_z = get_trailz(inbuffer, numbyte); + + if (numbyte >= TERM_LEN) { + if (n_curr_trailing_z >= TERM_LEN) { + /* terminator is complete */ + n_read_done++; + /* send back confirmation to the server */ + tiwrite(n_sockfd, "POS", TERM_YES); + } } - else { - closepager(pagerfp); + else if (n_curr_trailing_z == numbyte + && n_curr_trailing_z + n_last_trailing_z >= TERM_LEN) { + /* terminator is complete including the previous cycle */ + n_read_done++; + /* send back confirmation to the server */ + tiwrite(n_sockfd, "POS", TERM_YES); } - delete_all_lilimem(&sentinel); - close(n_sockfd); - n_broken_pipe = 0; - return 1; - } - else { - byte_written += fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); - if (!n_cgi && !strcmp(my_reftype, "ris")) { - sprintf(inbuffer, "%d dataset(s) sent.\n", n_setcount); - fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); + else if (n_curr_trailing_z == numbyte) { + /* terminator is still incomplete */ + n_last_trailing_z += n_curr_trailing_z; + continue; } - } + + /* write numbyte chars to output, unless this is the last chunk: we do not + want to write the terminating \0 */ + if (!n_broken_pipe) { + if (n_last_trailing_z) { + byte_written += fwrite(cs_term, sizeof(char), n_last_trailing_z, pagerfp); + } + byte_written += fwrite(inbuffer, sizeof(char), numbyte-n_curr_trailing_z, pagerfp); + if (!n_cgi && !strcmp(my_reftype, "ris")) { + sprintf(inbuffer, "%d dataset(s) sent.\n", n_setcount); + fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); + } + } + if (!n_read_done) { + n_last_trailing_z = n_curr_trailing_z; + } + } while (!n_read_done); + +/* numbyte = tread(n_sockfd, inbuffer, COMMAND_INBUF_LEN); */ + +/* if (numbyte == -1) { */ +/* cgi_header(CGI_PLAIN); */ +/* fprintf(errstream, "could not read from refdbd. Stop\n"); */ +/* if (n_file_open || n_file_append) { */ +/* close_outfile(pagerfp); */ +/* } */ +/* else { */ +/* closepager(pagerfp); */ +/* } */ +/* delete_all_lilimem(&sentinel); */ +/* close(n_sockfd); */ +/* n_broken_pipe = 0; */ +/* return 1; */ +/* } */ + +/* if (!*inbuffer) { */ +/* cgi_header(CGI_PLAIN); */ +/* fprintf(errstream, "server error. Stop.\n"); */ +/* if (n_file_open || n_file_append) { */ +/* close_outfile(pagerfp); */ +/* } */ +/* else { */ +/* closepager(pagerfp); */ +/* } */ +/* delete_all_lilimem(&sentinel); */ +/* close(n_sockfd); */ +/* n_broken_pipe = 0; */ +/* return 1; */ +/* } */ +/* else { */ +/* byte_written += fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); */ +/* if (!n_cgi && !strcmp(my_reftype, "ris")) { */ +/* sprintf(inbuffer, "%d dataset(s) sent.\n", n_setcount); */ +/* fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); */ +/* } */ +/* } */ /* send back confirmation to the server */ @@ -3492,4 +3551,6 @@ int n_keep_id = 0; /* indicates -k switch */ int n_send_result; + int n_curr_trailing_z = 0; + int n_last_trailing_z = 0; int i, j, k; /* guess what */ size_t byte_written = 0; @@ -3957,38 +4018,94 @@ } - numbyte = tread(n_sockfd, inbuffer, COMMAND_INBUF_LEN); - - if (numbyte == -1) { - cgi_header(CGI_PLAIN); - fprintf(errstream, "could not read from refdbd. Stop\n"); - if (n_file_open || n_file_append) { - close_outfile(pagerfp); - } - else { - closepager(pagerfp); + /* must read in loop */ + do { + numbyte = tread(n_sockfd, inbuffer, OUTBUF_LEN); + if (numbyte == -1) { + fprintf(stderr, "could not read from refdbd. Stop\n"); + if (n_file_open || n_file_append) { + close_outfile(pagerfp); + } + else { + closepager(pagerfp); + } + n_broken_pipe = 0; + return 1; } - delete_all_lilimem(&sentinel); - close(n_sockfd); - n_broken_pipe = 0; - return 1; - } - if (!*inbuffer) { - cgi_header(CGI_PLAIN); - fprintf(errstream, "server error. Stop.\n"); - if (n_file_open || n_file_append) { - close_outfile(pagerfp); + n_curr_trailing_z = get_trailz(inbuffer, numbyte); + + if (numbyte >= TERM_LEN) { + if (n_curr_trailing_z >= TERM_LEN) { + /* terminator is complete */ + n_read_done++; + /* send back confirmation to the server */ + tiwrite(n_sockfd, "POS", TERM_YES); + } } - else { - closepager(pagerfp); + else if (n_curr_trailing_z == numbyte + && n_curr_trailing_z + n_last_trailing_z >= TERM_LEN) { + /* terminator is complete including the previous cycle */ + n_read_done++; + /* send back confirmation to the server */ + tiwrite(n_sockfd, "POS", TERM_YES); } - delete_all_lilimem(&sentinel); - close(n_sockfd); - n_broken_pipe = 0; - return 1; - } - else { - byte_written += fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); - } + else if (n_curr_trailing_z == numbyte) { + /* terminator is still incomplete */ + n_last_trailing_z += n_curr_trailing_z; + continue; + } + + /* write numbyte chars to output, unless this is the last chunk: we do not + want to write the terminating \0 */ + if (!n_broken_pipe) { + if (n_last_trailing_z) { + byte_written += fwrite(cs_term, sizeof(char), n_last_trailing_z, pagerfp); + } + byte_written += fwrite(inbuffer, sizeof(char), numbyte-n_curr_trailing_z, pagerfp); + if (!n_cgi && !strcmp(my_reftype, "ris")) { + sprintf(inbuffer, "%d dataset(s) sent.\n", n_setcount); + fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); + } + } + + if (!n_read_done) { + n_last_trailing_z = n_curr_trailing_z; + } + } while (!n_read_done); + +/* numbyte = tread(n_sockfd, inbuffer, COMMAND_INBUF_LEN); */ + +/* if (numbyte == -1) { */ +/* cgi_header(CGI_PLAIN); */ +/* fprintf(errstream, "could not read from refdbd. Stop\n"); */ +/* if (n_file_open || n_file_append) { */ +/* close_outfile(pagerfp); */ +/* } */ +/* else { */ +/* closepager(pagerfp); */ +/* } */ +/* delete_all_lilimem(&sentinel); */ +/* close(n_sockfd); */ +/* n_broken_pipe = 0; */ +/* return 1; */ +/* } */ + +/* if (!*inbuffer) { */ +/* cgi_header(CGI_PLAIN); */ +/* fprintf(errstream, "server error. Stop.\n"); */ +/* if (n_file_open || n_file_append) { */ +/* close_outfile(pagerfp); */ +/* } */ +/* else { */ +/* closepager(pagerfp); */ +/* } */ +/* delete_all_lilimem(&sentinel); */ +/* close(n_sockfd); */ +/* n_broken_pipe = 0; */ +/* return 1; */ +/* } */ +/* else { */ +/* byte_written += fwrite(inbuffer, sizeof(char), strlen(inbuffer), pagerfp); */ +/* } */ /* send back confirmation to the server */ |