aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-22 04:10:31 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-09-22 04:13:02 +0200
commit99b9a6b80a4582282ff1b8f2b7d80011f5c59935 (patch)
tree0201b1d701c8c9daadffe7b2691ec17463b6c87b
parentAdd some info on that this repository contains. (diff)
downloadwireguard-apple-99b9a6b80a4582282ff1b8f2b7d80011f5c59935.tar.xz
wireguard-apple-99b9a6b80a4582282ff1b8f2b7d80011f5c59935.zip
PacketTunnelProvider: fix locking logic
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--WireGuardNetworkExtension/PacketTunnelProvider.swift17
1 files changed, 7 insertions, 10 deletions
diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift
index 64e9f5d4..9959decb 100644
--- a/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -192,22 +192,19 @@ class WireGuardContext {
readPacketCondition.signal()
}
+ func packetsRead(packets: [NEPacket]) {
+ outboundPackets.append(contentsOf: packets)
+ readPacketCondition.signal()
+ }
+
func readPacket(isTunnelClosed: inout Bool) -> NEPacket? {
if outboundPackets.isEmpty {
- let readPacketCondition = NSCondition()
readPacketCondition.lock()
- var packetsObtained: [NEPacket]?
- packetFlow.readPacketObjects { (packets: [NEPacket]) in
- packetsObtained = packets
- readPacketCondition.signal()
- }
+ packetFlow.readPacketObjects(completionHandler: packetsRead)
// Wait till the completion handler of packetFlow.readPacketObjects() finishes
- while packetsObtained == nil && !self.isTunnelClosed {
+ while outboundPackets.isEmpty && !self.isTunnelClosed {
readPacketCondition.wait()
}
- if let packetsObtained = packetsObtained {
- outboundPackets = packetsObtained
- }
readPacketCondition.unlock()
}
isTunnelClosed = self.isTunnelClosed