Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
fix: Potential hang fix during stream reading
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Jul 17, 2024
1 parent 182583e commit 7a2a24e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions BTFuse/src/BTFuseStreamReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ - (void) stream:(NSStream*) stream handleEvent:(NSStreamEvent) event {
}

switch (event) {
case NSStreamEventOpenCompleted: break;
case NSStreamEventHasBytesAvailable:
case NSStreamEventEndEncountered:
dispatch_semaphore_signal($readSemaphore);
break;
case NSStreamEventErrorOccurred:
NSLog(@"Stream encountered an error: %@", [stream streamError].localizedDescription);
$error = [stream streamError];
dispatch_semaphore_signal($readSemaphore);
break;
case NSStreamEventEndEncountered:
case NSStreamEventOpenCompleted:
default: break;
}
}

- (int64_t) read:(uint8_t*) buffer maxBytes:(uint32_t) max {
if (!$stream.hasBytesAvailable) {
if (!$stream.hasBytesAvailable && $stream.streamStatus != NSStreamEventEndEncountered) {
dispatch_semaphore_wait($readSemaphore, DISPATCH_TIME_FOREVER);
}

Expand Down

0 comments on commit 7a2a24e

Please sign in to comment.