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.

Reply via email to