Skip to content

Commit

Permalink
Fix false positive triggering parallel reads unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 28, 2024
1 parent 4b3f872 commit ccfc2b8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Monal/Classes/MLStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ -(void) generateEvent:(NSStreamEvent) event;
@interface MLInputStream()
{
NSMutableData* _buf;
BOOL _reading;
volatile __block BOOL _reading;
}
@property (atomic, readonly) void (^incoming_data_handler)(NSData* _Nullable, BOOL, NSError* _Nullable);
@end

@interface MLOutputStream()
{
unsigned long _writing;
volatile __block unsigned long _writing;
}
@end

Expand Down Expand Up @@ -80,7 +80,7 @@ -(instancetype) initWithSharedState:(MLSharedStreamState*) shared
_buf = [NSMutableData new];
_reading = NO;

//this handler will be called by our framer or the schedule_read method
//this handler will be called by the schedule_read method
//since the framer swallows all data, nw_connection_receive() and the framer cannot race against each other and deliver reordered data
weakify(self);
_incoming_data_handler = ^(NSData* _Nullable content, BOOL is_complete, NSError* _Nullable st_error) {
Expand All @@ -89,7 +89,10 @@ -(instancetype) initWithSharedState:(MLSharedStreamState*) shared
return;

DDLogVerbose(@"Incoming data handler called with is_complete=%@, st_error=%@, content=%@", bool2str(is_complete), st_error, content);
self->_reading = NO;
@synchronized(self.shared_state) {
DDLogVerbose(@"Setting _reading to no...");
self->_reading = NO;
}

//handle content received
if(content != NULL)
Expand Down Expand Up @@ -197,6 +200,7 @@ -(void) schedule_read
//TODO: does this ever happen??
unreachable(@"Not calling nw_connection_receive: already reading!");
}
DDLogVerbose(@"Setting _reading to yes...");
_reading = YES;

if(self.shared_state.framer != nil)
Expand Down

0 comments on commit ccfc2b8

Please sign in to comment.