Hi jules,
I need a callback during a download process, so I added some codes to the URL class and it can now work to my anticipation. Just want to know if you want to add a callback like this in the current juce.
What I did is simply reusing the OpenStreamCallback you made for POST… Storing the callback and the context and using them in the read(xx,xx) function in juce_mac_Network.mm
bool start (URL::OpenStreamProgressCallback* callback, void* context)
{
testCallback = callback;
testCallbackCtx = context;
startThread();
while (isThreadRunning() && ! initialised)
{
if (callback != nullptr)
callback (context, -1, (int) [[request HTTPBody] length]);
Thread::sleep (1);
}
return connection != nil && ! hasFailed;
}
int read (char* dest, int numBytes)
{
int numDone = 0;
while (numBytes > 0)
{
const int 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];
numDone += available;
numBytes -= available;
dest += available;
testCallback(testCallbackCtx, available, thisVaribleSeemsUseless);
}
else
{
if (hasFailed || hasFinished)
break;
Thread::sleep (1);
}
}
return numDone;
}
and of course
URL::OpenStreamProgressCallback* testCallback;
void *testCallbackCtx;
Hope I can see an official codes for this?
Thanks