didReceiveData (NSData* newData) doesn't call callback


#1

I fixed it this way:

 

in juce_mac_Network.mm



 bool start (URL::OpenStreamProgressCallback* callback, void* context)
    {
        fCallback = callback;
        fContext = context;

        startThread();

        while (isThreadRunning() && ! initialised)
        {
            if (fCallback != nullptr)
                fCallback (fContext, -1, (int) [[request HTTPBody] length]);

            Thread::sleep (1);
        }

        return connection != nil && ! hasFailed;
    }


........


    void didReceiveData (NSData* newData)
    {
        const ScopedLock sl (dataLock);
        [data appendData: newData];
        initialised = true;

        if (fCallback != nullptr)
            fCallback (fContext, [newData length], (int) [[request HTTPBody] length]);
    }





......

private:

    URL::OpenStreamProgressCallback* fCallback;
    void* fContext;

#2

ok.. but I think it might end up calling it on the wrong thread. Can you explain a bit more about what's not working, as I assumed that was ok, and had used the functionality myself.


#3

What I am trying to do is display a bar showing what percentage is downloaded. My callback sends an async message so the drawing is done in another thread. Without my changes in code, the callback is only called on the start of the download with -1 as bytesSent.


#4

You're not trying to run this on the GUI thread, are you? You need to run longer operations like this on a background thread.


#5

No I'm not,

In the documentation it says



//==============================================================================
    /** This callback function can be used by the createInputStream() method.

        It allows your app to receive progress updates during a lengthy POST operation. If you
        want to continue the operation, this should return true, or false to abort.
    */
    typedef bool (OpenStreamProgressCallback) (void* context, int bytesSent, int totalBytes);

Which I understood to be a possiblity to draw a progress bar (again: in another thread). But looking into the code I can see that before my changes this never gets called apart from the beginning.

This same thing seems to also be the case in the Windows implementation.

 

 

As I read again I see that this is for a POST operation and I am using a GET, is there a possibility, (other then what I did now) to create a progress bar for a GET operation?


#6

No.. I don't see how there could be a progress callback for a GET because there's almost no data for it to upload (?)


#7

Just to be clear this is about a user downloading a big file to their computer through a GET command, and letting them know how far their download is. As far as I understand not a strange use of GET.


#8

This callback is for the progress of UPloading the POST data, not downloading the stream itself!


#9

Ok, too bad. Would you feel like implementing something I described? Or is there a way to already do this? My code above seems to work for my use case, but might not fit in the juce logic.


#10

huh..?

It's an input stream - if you want to measure downlaod progress, you can just keep track of how many bytes you've read from the stream so far, same as you would if it was any other kind of input stream.


#11

Ah ok, I misunderstood, thanks.