Ok, that’s interesting.  The synchronous download worked on the background 
thread.  This works now with -s NO_EXIT_RUNTIME=1.  It had no effect on the 
asynchronous download on a background thread.  I still get a call to 
downloadFailed with a status of 0.  

> On Aug 9, 2017, at 1:06 PM, Jukka Jylänki <juj...@gmail.com> wrote:
> 
> Hmm, can you try specifying the following attributes for the download?
> 
> attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY |
> EMSCRIPTEN_FETCH_SYNCHRONOUS | EMSCRIPTEN_FETCH_REPLACE;
> 
> Also there is a linker flag -s FETCH_DEBUG=1 that can show more information.
> 
> 2017-08-09 22:45 GMT+03:00 Scott Watson <wswat...@gmail.com>:
>> First, thank you for the assistance!
>> 
>> -s NO_EXIT_RUNTIME=1 had no effect.  Actually, I think you get that
>> automatically with -s USE_PTHREADS=1 don't you?
>> 
>> I switched to using pthreads directly with no effect either.
>> 
>> 
>> On Wednesday, August 9, 2017 at 12:35:20 PM UTC-7, jj wrote:
>>> 
>>> First thing is to remember to also compile with -s NO_EXIT_RUNTIME=1,
>>> since once main() exits, it will tear down the application runtime,
>>> along with all threads, so the linker flag will keep it running after
>>> exiting main. I wonder if that already will solve the issue?
>>> 
>>> Another note is that C++11 threading is known to have some bugs, the
>>> pthread_create() API is robust and unit tested. (If someone knows of a
>>> good open source unit test suite for C++11 threading, I'm all ears)
>>> 
>>> 2017-08-09 21:37 GMT+03:00 Scott Watson <wswa...@gmail.com>:
>>>> I am having trouble porting our application to asm.js.  We have a class
>>>> that
>>>> handles HTTP GETs for us, that I am trying to port using the
>>>> emscripten_fetch api.
>>>> 
>>>> I can only get the asynchronous fetch to work, and only when called on
>>>> the
>>>> main thread.  I can't get synchronous to work at all.  Using the sample
>>>> code
>>>> from:
>>>> https://kripken.github.io/emscripten-site/docs/api_reference/fetch.html,
>>>> I
>>>> built this.
>>>> 
>>>>    // main.cpp
>>>> 
>>>>    #include <thread>
>>>>    #include <iostream>
>>>> 
>>>>    #include <emscripten/fetch.h>
>>>> 
>>>>    void downloadSucceeded(emscripten_fetch_t *fetch) {
>>>>      printf("Finished asynchronously downloading %llu bytes from URL
>>>> %s.\n", fetch->numBytes, fetch->url);
>>>>      // The data is now available at fetch->data[0] through
>>>> fetch->data[fetch->numBytes-1];
>>>>      emscripten_fetch_close(fetch); // Free data associated with the
>>>> fetch.
>>>>    }
>>>> 
>>>>    void downloadFailed(emscripten_fetch_t *fetch) {
>>>>      printf("Downloading %s asynchronously failed, HTTP failure status
>>>> code: %d.\n", fetch->url, fetch->status);
>>>>      //emscripten_fetch_close(fetch); // Also free data on failure.
>>>>    }
>>>> 
>>>>    void worker()
>>>>    {
>>>>      emscripten_fetch_attr_t attr;
>>>> 
>>>>      emscripten_fetch_attr_init(&attr);
>>>> 
>>>>      strcpy(attr.requestMethod, "GET");
>>>> 
>>>>      attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
>>>>      attr.onsuccess = downloadSucceeded;
>>>>      attr.onerror = downloadFailed;
>>>> 
>>>>      emscripten_fetch(&attr, "http://localhost/VOD/nangu/00000041.ts";);
>>>> //
>>>> Blocks here until the operation is complete.
>>>>    }
>>>> 
>>>>    int main()
>>>>    {
>>>>        // worker();
>>>>        std::thread test1(worker);
>>>>    }
>>>> 
>>>> I am building it using:
>>>> 
>>>>    emcc main.cpp -o $(OUTPUT_FOLDER)/thread_test.html -s USE_PTHREADS=1
>>>> -s
>>>> PTHREAD_POOL_SIZE=5 -s FETCH=1
>>>> 
>>>> My downloadFailed method is being called with a 'fetch->status' of 0.
>>>> If I
>>>> call the 'worker()' method directly I get the expected behavior.
>>>> 
>>>> I am tearing my hair out here.  I have googled everything I can think of
>>>> to
>>>> no avail.
>>>> 
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups
>>>> "emscripten-discuss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an
>>>> email to emscripten-discuss+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>> 
>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to emscripten-discuss+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "emscripten-discuss" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/emscripten-discuss/wBCcSKPZsx8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> emscripten-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to