diff --git a/Audio/Chain/InputNode.m b/Audio/Chain/InputNode.m index fa6933eb7..8262e732a 100644 --- a/Audio/Chain/InputNode.m +++ b/Audio/Chain/InputNode.m @@ -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) { diff --git a/Plugins/HTTPSource/HTTPSource.mm b/Plugins/HTTPSource/HTTPSource.mm index d54d48eab..af845c6d5 100644 --- a/Plugins/HTTPSource/HTTPSource.mm +++ b/Plugins/HTTPSource/HTTPSource.mm @@ -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;