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.
// 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;
}
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.