fetch: indicate an error if the connection was terminated prematurely
authorFelix Fietkau <nbd@openwrt.org>
Wed, 7 May 2014 21:21:52 +0000 (23:21 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 7 May 2014 21:21:52 +0000 (23:21 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
uclient-fetch.c
uclient-http.c
uclient.c
uclient.h

index 8dcb97b1349eedcea101c1fcae14ca280b7b89ee..6a27cde159ec0cfab90aee4cc9ece551a3dfb3ee 100644 (file)
@@ -151,6 +151,11 @@ static void init_request(struct uclient *cl)
 
 static void eof_cb(struct uclient *cl)
 {
+       if (!cl->data_eof) {
+               if (!quiet)
+                       fprintf(stderr, "Connection reset prematurely\n");
+               error_ret = 4;
+       }
        request_done(cl);
 }
 
index ee161e6bd21507f946cc97dddc39dedcecf41ab7..9652fb8f7cd9a9d5457a44522fddb5b919e16ba9 100644 (file)
@@ -928,8 +928,10 @@ uclient_http_read(struct uclient *cl, char *buf, unsigned int len)
                read_len += sep + 2 - data;
                data = sep + 2;
 
-               if (!uh->read_chunked)
+               if (!uh->read_chunked) {
                        uh->eof = true;
+                       uh->uc.data_eof = true;
+               }
        }
 
        if (len > data_end - data)
@@ -945,8 +947,10 @@ uclient_http_read(struct uclient *cl, char *buf, unsigned int len)
                        len = uh->content_length;
 
                uh->content_length -= len;
-               if (!uh->content_length)
+               if (!uh->content_length) {
                        uh->eof = true;
+                       uh->uc.data_eof = true;
+               }
        }
 
        if (len > 0) {
index fb450699654e86ef370575c03cf12192429bc348..ab2d5b6c393fa6c14d03693ae76f5dbe392767f2 100644 (file)
--- a/uclient.c
+++ b/uclient.c
@@ -267,6 +267,7 @@ void __hidden uclient_backend_set_eof(struct uclient *cl)
 
 void __hidden uclient_backend_reset_state(struct uclient *cl)
 {
+       cl->data_eof = false;
        cl->eof = false;
        cl->error_code = 0;
        uloop_timeout_cancel(&cl->timeout);
index ddc8b7845f9baaaee13ab766c93db706b191ff33..d5a0d5b4f804dd68523c4993921fe50edc8d1da3 100644 (file)
--- a/uclient.h
+++ b/uclient.h
@@ -62,6 +62,7 @@ struct uclient {
        void *priv;
 
        bool eof;
+       bool data_eof;
        int error_code;
        int status_code;
        struct blob_attr *meta;