From 9ceca0a12166cefdf07aedc3c187fdd2f72fdec8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 7 May 2014 23:21:52 +0200 Subject: [PATCH] fetch: indicate an error if the connection was terminated prematurely Signed-off-by: Felix Fietkau --- uclient-fetch.c | 5 +++++ uclient-http.c | 8 ++++++-- uclient.c | 1 + uclient.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/uclient-fetch.c b/uclient-fetch.c index 8dcb97b..6a27cde 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -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); } diff --git a/uclient-http.c b/uclient-http.c index ee161e6..9652fb8 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -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) { diff --git a/uclient.c b/uclient.c index fb45069..ab2d5b6 100644 --- 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); diff --git a/uclient.h b/uclient.h index ddc8b78..d5a0d5b 100644 --- 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; -- 2.11.0