From bacf61d153ef2ca7c88267a27d4998f2939433a2 Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Sun, 5 Aug 2018 22:59:34 +0200 Subject: Call read packets on background queue to allow waiting for signal. Signed-off-by: Jason A. Donenfeld --- WireGuardNetworkExtension/WireGuardGoWrapper.m | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'WireGuardNetworkExtension') 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 * _Nonnull packets, NSArray * _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 * _Nonnull packets, NSArray * _Nonnull protocols) { + [wrapper.packets addObjectsFromArray:packets]; + [wrapper.protocols addObjectsFromArray:protocols]; + [wrapper.condition signal]; + }]; + }); [wrapper.condition wait]; } -- cgit v1.2.3-59-g8ed1b