From 7e2e65f16003fc68511c3321cb25fec0f8097baa Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 12 Aug 2018 23:05:21 -0700 Subject: [PATCH] bridge: don't put on another thread --- .../WireGuardGoWrapper.m | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m index 8deb527..2f5a558 100644 --- a/WireGuardNetworkExtension/WireGuardGoWrapper.m +++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m @@ -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 * _Nonnull packets, NSArray * _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 * _Nonnull packets, NSArray * _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];