bridge: don't put on another thread

This commit is contained in:
Jason A. Donenfeld 2018-08-12 23:05:21 -07:00
parent 412b21a7ce
commit 7e2e65f160
1 changed files with 10 additions and 11 deletions

View File

@ -94,18 +94,17 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
return 0;
}
if (wrapper.packets.count == 0) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[wrapper.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) {
[wrapper.packets addObjectsFromArray:packets];
[wrapper.protocols addObjectsFromArray:protocols];
os_log_debug([WireGuardGoWrapper log], "do_read - signal - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread);
[wrapper.condition signal];
}];
});
if (!wrapper.packets.count) {
[wrapper.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) {
[wrapper.condition signal];
[wrapper.packets addObjectsFromArray:packets];
[wrapper.protocols addObjectsFromArray:protocols];
os_log_debug([WireGuardGoWrapper log], "do_read - signal - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread);
[wrapper.condition signal];
}];
os_log_debug([WireGuardGoWrapper log], "do_read - wait - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread);
[wrapper.condition wait];
while (!wrapper.packets.count)
[wrapper.condition wait];
}
NSData *packet = [wrapper.packets objectAtIndex:0];