Changeset: 3527803c4a1d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3527803c4a1d
Modified Files:
        common/stream/bs.c
        common/stream/stream.h
        common/stream/stream_internal.h
        sql/backends/monet5/sql_bincopyfrom.c
Branch: default
Log Message:

Get rid of set_prompting

We have the dedicated mapi_request_upload now.


diffs (203 lines):

diff --git a/common/stream/bs.c b/common/stream/bs.c
--- a/common/stream/bs.c
+++ b/common/stream/bs.c
@@ -17,8 +17,6 @@
  * indicated by an empty block (i.e. just a count of 0).
  */
 
-static ssize_t bs_read_internal(stream *restrict ss, void *restrict buf, 
size_t elmsize, size_t cnt);
-
 static bs *
 bs_create(void)
 {
@@ -168,29 +166,6 @@ bs_flush(stream *ss, mnstr_flush_level f
 ssize_t
 bs_read(stream *restrict ss, void *restrict buf, size_t elmsize, size_t cnt)
 {
-       ssize_t ret = bs_read_internal(ss, buf, elmsize, cnt);
-       if (ret != 0 || ss->eof)
-               return ret;
-
-       bs *b = (bs*) ss-> stream_data.p;
-       if (b->prompt == NULL || b->pstream == NULL)
-               return 0;
-
-       // before returning the 0 we send the prompt and make another attempt.
-       if (mnstr_write(b->pstream, b->prompt, strlen(b->prompt), 1) != 1)
-               return -1;
-       if (mnstr_flush(b->pstream, MNSTR_FLUSH_DATA) < 0)
-               return -1;
-
-       // if it succeeds, return that to the client.
-       // if it's still a block boundary, return that to the client.
-       // if there's an error, return that to the client.
-       return bs_read_internal(ss, buf, elmsize, cnt);
-}
-
-static ssize_t
-bs_read_internal(stream *restrict ss, void *restrict buf, size_t elmsize, 
size_t cnt)
-{
        bs *s;
        size_t todo = cnt * elmsize;
        size_t n;
@@ -397,13 +372,3 @@ block_stream(stream *s)
 
        return ns;
 }
-
-void
-set_prompting(stream *block_stream, const char *prompt, stream *prompt_stream)
-{
-       if (isa_block_stream(block_stream)) {
-               bs *bs = block_stream->stream_data.p;
-               bs->prompt = prompt;
-               bs->pstream = prompt_stream;
-       }
-}
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -219,7 +219,6 @@ stream_export buffer *mnstr_get_buffer(s
 stream_export stream *block_stream(stream *s); // mapi.c, mal_mapi.c, 
client.c, merovingian
 stream_export bool isa_block_stream(const stream *s); // mapi.c, mal_client.c, 
remote.c, sql_scenario.c/sqlReader, sql_scan.c
 stream_export stream *bs_stream(stream *s); // unused
-stream_export void set_prompting(stream *block_stream, const char *prompt, 
stream *prompt_stream);
 
 
 stream_export stream *mapi_request_upload(const char *filename, bool binary, 
stream *from, stream *to);
diff --git a/common/stream/stream_internal.h b/common/stream/stream_internal.h
--- a/common/stream/stream_internal.h
+++ b/common/stream/stream_internal.h
@@ -271,8 +271,6 @@ struct bs {
        unsigned itotal;        /* amount available in current read block */
        size_t blks;            /* read/writen blocks (possibly partial) */
        size_t bytes;           /* read/writen bytes */
-       const char *prompt;     /* on eof, first try to send this then try 
again */
-       stream *pstream;        /* stream to send prompts on */
        char buf[BLOCK];        /* the buffered data (minus the size of
                                 * size-short */
 };
diff --git a/sql/backends/monet5/sql_bincopyfrom.c 
b/sql/backends/monet5/sql_bincopyfrom.c
--- a/sql/backends/monet5/sql_bincopyfrom.c
+++ b/sql/backends/monet5/sql_bincopyfrom.c
@@ -543,70 +543,6 @@ load_column(struct type_rec *rec, const 
                return msg;
 }
 
-
-static str
-start_mapi_file_upload(backend *be, str path, stream **s)
-{
-       str msg = MAL_SUCCEED;
-       *s = NULL;
-
-       stream *ws = be->mvc->scanner.ws;
-       bstream *bs = be->mvc->scanner.rs;
-       stream *rs = bs->s;
-       assert(isa_block_stream(ws));
-       assert(isa_block_stream(rs));
-
-       mnstr_write(ws, PROMPT3, sizeof(PROMPT3)-1, 1);
-       mnstr_printf(ws, "rb %s\n", path);
-       mnstr_flush(ws, MNSTR_FLUSH_DATA);
-       while (!bs->eof)
-               bstream_next(bs);
-       char buf[80];
-       if (mnstr_readline(rs, buf, sizeof(buf)) > 1) {
-               msg = createException(IO, "sql.importColumn", "Error %s", buf);
-               goto end;
-       }
-       set_prompting(rs, PROMPT2, ws);
-
-       *s = rs;
-end:
-       return msg;
-}
-
-
-static str
-finish_mapi_file_upload(backend *be, bool eof_reached)
-{
-       str msg = MAL_SUCCEED;
-       stream *ws = be->mvc->scanner.ws;
-       bstream *bs = be->mvc->scanner.rs;
-       stream *rs = bs->s;
-       assert(isa_block_stream(ws));
-       assert(isa_block_stream(rs));
-
-       set_prompting(rs, NULL, NULL);
-       if (!eof_reached) {
-               // Probably due to an error. Read until message boundary.
-               char buf[8190];
-               while (1) {
-                       ssize_t nread = mnstr_read(rs, buf, 1, sizeof(buf));
-                       if (nread > 0)
-                               continue;
-                       if (nread < 0)
-                               msg = createException(
-                                       IO, "sql.importColumn",
-                                       "while syncing read stream: %s", 
mnstr_peek_error(rs));
-                       break;
-               }
-       }
-       mnstr_write(ws, PROMPT3, sizeof(PROMPT3)-1, 1);
-       mnstr_flush(ws, MNSTR_FLUSH_DATA);
-
-       return msg;
-}
-
-
-
 /* Import a single file into a new BAT.
  */
 static str
@@ -620,7 +556,6 @@ importColumn(backend *be, bat *ret, BUN 
        int gdk_type;
        BAT *bat = NULL;
        stream *stream_to_close = NULL;
-       bool do_finish_mapi = false;
        int eof_reached = -1; // 1 = read to the end; 0 = stopped reading 
early; -1 = unset, a bug.
 
        // This one is not managed by the end: block
@@ -645,15 +580,21 @@ importColumn(backend *be, bat *ret, BUN 
 
        // Open the input stream
        if (onclient) {
-               s = NULL;
-               do_finish_mapi = true;
-               msg = start_mapi_file_upload(be, path, &s);
-               if (msg != MAL_SUCCEED)
-                       goto end;
+
+                       stream *ws = be->mvc->scanner.ws;
+                       bstream *bs = be->mvc->scanner.rs;
+                       while (!bs->eof)
+                               bstream_next(bs);
+                       stream *rs = bs->s;
+                       assert(isa_block_stream(ws));
+                       assert(isa_block_stream(rs));
+                       s = stream_to_close = mapi_request_upload(path, true, 
rs, ws);
        } else {
                s = stream_to_close = open_rstream(path);
-               if (s == NULL)
-                       bailout("Couldn't open '%s' on server: %s", path, 
mnstr_peek_error(NULL));
+       }
+       if (!s) {
+               msg = mnstr_error(NULL);
+               goto end;
        }
 
        // Do the work
@@ -667,12 +608,6 @@ importColumn(backend *be, bat *ret, BUN 
 
        // Fall through into the end block which will clean things up
 end:
-       if (do_finish_mapi) {
-               str msg1 = finish_mapi_file_upload(be, eof_reached == 1);
-               if (msg == MAL_SUCCEED)
-                       msg = msg1;
-       }
-
        if (stream_to_close)
                close_stream(stream_to_close);
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to