From 974427fd0afc3bf858f7b0a38f626bc3fd17ae61 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Thu, 15 Jan 2015 08:40:24 +0200 Subject: [PATCH] Properly handle read errors (EOF and errors) --- modules/remotebackend/httpconnector.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/remotebackend/httpconnector.cc b/modules/remotebackend/httpconnector.cc index efef0123b..b74d105a9 100644 --- a/modules/remotebackend/httpconnector.cc +++ b/modules/remotebackend/httpconnector.cc @@ -389,7 +389,11 @@ int HTTPConnector::recv_message(rapidjson::Document &output) { try { t0 = time((time_t*)NULL); while(arl.ready() == false && (labs(time((time_t*)NULL) - t0) <= timeout/1000)) { - rd = d_socket->readWithTimeout(buffer, sizeof(buffer), timeout); // if rd<=0 this will throw + rd = d_socket->readWithTimeout(buffer, sizeof(buffer), timeout); + if (rd==0) + throw NetworkError("EOF while reading"); + if (rd<0) + throw NetworkError(std::string(strerror(rd))); buffer[rd] = 0; arl.feed(std::string(buffer, rd)); } -- 2.40.0