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 8dcb97b..6a27cde 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 ee161e6..9652fb8 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 fb45069..ab2d5b6 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 ddc8b78..d5a0d5b 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;