Added timeout and chillout logic to the HTTP source so it doesn't freak out when there's no data available.
This commit is contained in:
parent
2b55b8978b
commit
bf7b2c0a2b
2 changed files with 27 additions and 4 deletions
|
@ -28,7 +28,7 @@
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int status = _get->get_status();
|
int status = _get->get_status();
|
||||||
|
|
||||||
if (status < 0 || status > 1) {
|
if (status != 0 && status != 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +75,34 @@
|
||||||
{
|
{
|
||||||
int totalRead = 0;
|
int totalRead = 0;
|
||||||
|
|
||||||
|
NSTimeInterval timeout = 30;
|
||||||
|
BOOL timingOut = NO;
|
||||||
|
|
||||||
while (totalRead < amount) {
|
while (totalRead < amount) {
|
||||||
int result = _get->run();
|
int result = _get->run();
|
||||||
int amountRead = _get->get_bytes((char *)((uint8_t *)buffer) + totalRead, amount - totalRead);
|
int amountRead = _get->get_bytes((char *)((uint8_t *)buffer) + totalRead, amount - totalRead);
|
||||||
|
|
||||||
if (result != 0 && 0 == amountRead) break;
|
if (0 == amountRead) {
|
||||||
|
if (0 != result) break;
|
||||||
|
|
||||||
|
if (NO == timingOut) {
|
||||||
|
timingOut = YES;
|
||||||
|
timeout = [NSDate timeIntervalSinceReferenceDate] + 30;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (timeout < [NSDate timeIntervalSinceReferenceDate]) {
|
||||||
|
NSLog(@"Timed out!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sigh. We should just use blocking IO.
|
||||||
|
usleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timingOut = NO;
|
||||||
|
}
|
||||||
|
|
||||||
totalRead += amountRead;
|
totalRead += amountRead;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue