Added timeout and chillout logic to the HTTP source so it doesn't freak out when there's no data available.

CQTexperiment
vspader 2009-03-06 21:58:50 -08:00
parent 2b55b8978b
commit bf7b2c0a2b
2 changed files with 27 additions and 4 deletions

View File

@ -120,7 +120,7 @@
int framesToRead = (CHUNK_SIZE - amountInBuffer)/bytesPerFrame;
int framesRead = [decoder readAudio:((char *)inputBuffer) + amountInBuffer frames:framesToRead];
amountInBuffer += (framesRead * bytesPerFrame);
if (framesRead <= 0)
{
if (initialBufferFilled == NO) {

View File

@ -28,7 +28,7 @@
for(;;) {
int status = _get->get_status();
if (status < 0 || status > 1) {
if (status != 0 && status != 1) {
break;
}
@ -75,15 +75,38 @@
{
int totalRead = 0;
NSTimeInterval timeout = 30;
BOOL timingOut = NO;
while (totalRead < amount) {
int result = _get->run();
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;
}
_byteCount += totalRead;
return totalRead;