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) {
- delete d_socket;
- d_socket = NULL;
- fail = true;
- break;
- }
+ rd = d_socket->readWithTimeout(buffer, sizeof(buffer), timeout); // if rd<=0 this will throw
buffer[rd] = 0;
arl.feed(std::string(buffer, rd));
}
// timeout occured.
- if (arl.ready() == false) {
- L<<Logger::Error<<"While reading from HTTP endpoint "<<d_addr.toStringWithPort()<<": timeout"<<std::endl;
- delete d_socket;
- d_socket = NULL;
- fail = true;
- }
+ if (arl.ready() == false)
+ throw NetworkError("timeout");
} catch (NetworkError &ne) {
L<<Logger::Error<<"While reading from HTTP endpoint "<<d_addr.toStringWithPort()<<": "<<ne.what()<<std::endl;
delete d_socket;