Browse Source

fetch: indicate an error if the connection was terminated prematurely

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Felix Fietkau 10 years ago
parent
commit
9ceca0a121
4 changed files with 13 additions and 2 deletions
  1. 5 0
      uclient-fetch.c
  2. 6 2
      uclient-http.c
  3. 1 0
      uclient.c
  4. 1 0
      uclient.h

+ 5 - 0
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);
 }
 

+ 6 - 2
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) {

+ 1 - 0
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);

+ 1 - 0
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;