From f9961e99387576b5e2ab618ed0e817d5873caf78 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 9 Mar 2020 14:43:15 +0000 Subject: [PATCH] Fixed a bug in the previous commit --- modules/juce_core/native/juce_mac_Network.mm | 26 ++++++-------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/modules/juce_core/native/juce_mac_Network.mm b/modules/juce_core/native/juce_mac_Network.mm index 2512a23663..2af45dcc71 100644 --- a/modules/juce_core/native/juce_mac_Network.mm +++ b/modules/juce_core/native/juce_mac_Network.mm @@ -188,21 +188,15 @@ public: int read (char* dest, int numBytes) { - int numDone = 0, dataLength = 0; - - { - const ScopedLock sl (dataLock); - dataLength = (int) [data length]; - } + int numDone = 0; while (numBytes > 0) { - auto available = jmin (numBytes, dataLength); + const ScopedLock sl (dataLock); + auto available = jmin (numBytes, (int) [data length]); if (available > 0) { - const ScopedLock sl (dataLock); - [data getBytes: dest length: (NSUInteger) available]; [data replaceBytesInRange: NSMakeRange (0, (NSUInteger) available) withBytes: nil length: 0]; @@ -215,6 +209,7 @@ public: if (hasFailed || hasFinished) break; + const ScopedUnlock ul (dataLock); Thread::sleep (1); } } @@ -749,21 +744,15 @@ public: int read (char* dest, int numBytes) { - int numDone = 0, dataLength = 0; - - { - const ScopedLock sl (dataLock); - dataLength = (int) [data length]; - } + int numDone = 0; while (numBytes > 0) { - auto available = jmin (numBytes, dataLength); + const ScopedLock sl (dataLock); + auto available = jmin (numBytes, (int) [data length]); if (available > 0) { - const ScopedLock sl (dataLock); - [data getBytes: dest length: (NSUInteger) available]; [data replaceBytesInRange: NSMakeRange (0, (NSUInteger) available) withBytes: nil length: 0]; @@ -776,6 +765,7 @@ public: if (hasFailed || hasFinished) break; + const ScopedUnlock sul (dataLock); Thread::sleep (1); } }