bridge: don't put on another thread

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-08-12 23:05:21 -07:00
parent a81e8dcf3c
commit 76a001dbe0
1 changed files with 10 additions and 11 deletions

View File

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