Changeset: 2981cbc8e467 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2981cbc8e467
Modified Files:
        common/stream/bs.c
        common/stream/mapi_stream.c
Branch: Mar2025
Log Message:

Improve error propagation during file transfer


diffs (74 lines):

diff --git a/common/stream/bs.c b/common/stream/bs.c
--- a/common/stream/bs.c
+++ b/common/stream/bs.c
@@ -93,8 +93,14 @@ bs_write(stream *restrict ss, const void
                         * to the left */
                        blksize <<= 1;
                        if (!mnstr_writeSht(ss->inner, (int16_t) blksize) ||
-                           ss->inner->write(ss->inner, s->buf, 1, s->nr) != 
(ssize_t) s->nr) {
-                               mnstr_copy_error(ss, ss->inner);
+                           ss->inner->write(ss->inner, s->buf, 1, s->nr) != 
(ssize_t) s->nr
+                       ) {
+                               if (mnstr_errnr(ss->inner) != MNSTR_NO__ERROR) {
+                                       mnstr_copy_error(ss, ss->inner);
+                               } else {
+                                       mnstr_set_error(ss, MNSTR_WRITE_ERROR, 
"connection closed unexpectedly");
+                               }
+
                                s->nr = 0; /* data is lost due to error */
                                return -1;
                        }
diff --git a/common/stream/mapi_stream.c b/common/stream/mapi_stream.c
--- a/common/stream/mapi_stream.c
+++ b/common/stream/mapi_stream.c
@@ -56,6 +56,7 @@ discard(stream *s)
 struct mapi_filetransfer {
        stream *from_client; // set to NULL after sending MAPI_PROMPT3
        stream *to_client; // set to NULL when client sends empty
+       bstream *bs;
 };
 
 static ssize_t
@@ -77,7 +78,8 @@ upload_read(stream *restrict s, void *re
                        mnstr_write(state->to_client, PROMPT2, strlen(PROMPT2), 
1) != 1
                ||      mnstr_flush(state->to_client, MNSTR_FLUSH_ALL) < 0
        ) {
-               mnstr_set_error(s, mnstr_errnr(state->to_client), "%s", 
mnstr_peek_error(state->to_client));
+               state->bs->pos = state->bs->len;
+               mnstr_copy_error(s, state->to_client);
                return -1;
        }
 
@@ -92,6 +94,7 @@ upload_read(stream *restrict s, void *re
                state->from_client = NULL;
                return nread;
        } else {
+               state->bs->pos = state->bs->len;
                mnstr_set_error(s, mnstr_errnr(state->from_client), "%s", 
mnstr_peek_error(state->from_client));
                return -1;
        }
@@ -116,7 +119,15 @@ download_write(stream *restrict s, const
 {
        struct mapi_filetransfer *state = s->stream_data.p;
        stream *to = state->to_client;
-       return to->write(to, buf, elmsize, cnt);
+       ssize_t res = to->write(to, buf, elmsize, cnt);
+       if (res < 0) {
+               state->bs->pos = state->bs->len;
+               mnstr_copy_error(s, to);
+       } else if (res == 0) {
+               assert(to->eof);
+               s->eof = to->eof;
+       }
+       return res;
 }
 
 static void
@@ -205,6 +216,7 @@ setup_transfer(const char *req, const ch
        }
        state->from_client = rs;
        state->to_client = ws;
+       state->bs = bs;
        s->stream_data.p = state;
 end:
        if (msg) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to