aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuardNetworkExtension
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-05 22:59:34 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-05 22:59:34 +0200
commitbacf61d153ef2ca7c88267a27d4998f2939433a2 (patch)
treec98133a9e74ce583e74be036660f980184ce1107 /WireGuardNetworkExtension
parentA handle of zero is also correct. (diff)
downloadwireguard-apple-bacf61d153ef2ca7c88267a27d4998f2939433a2.tar.xz
wireguard-apple-bacf61d153ef2ca7c88267a27d4998f2939433a2.zip
Call read packets on background queue to allow waiting for signal.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuardNetworkExtension')
-rw-r--r--WireGuardNetworkExtension/WireGuardGoWrapper.m13
1 files changed, 7 insertions, 6 deletions
diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m
index 8259b1a..cda62b4 100644
--- a/WireGuardNetworkExtension/WireGuardGoWrapper.m
+++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m
@@ -85,12 +85,13 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
if (wrapper.packets.count == 0) {
- [wrapper.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) {
- [wrapper.packets addObjectsFromArray:packets];
- [wrapper.protocols addObjectsFromArray:protocols];
- // TODO make sure that the completion handler and the do_read are not performed on the same thread.
- [wrapper.condition signal];
- }];
+ 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];
+ [wrapper.condition signal];
+ }];
+ });
[wrapper.condition wait];
}