Here are the internals of my urlLoader class for emscripten which uses 
emscripten_async_wget_data():

https://github.com/floooh/oryol/blob/master/code/Modules/HTTP/emsc/emscURLLoader.cc

Here's how it compares to CURL with the 'easy' API:

https://github.com/floooh/oryol/blob/master/code/Modules/HTTP/curl/curlURLLoader.cc

And WinHttp:

https://github.com/floooh/oryol/blob/master/code/Modules/HTTP/windows/winURLLoader.cc

There's an important difference: both the curl and the WinHttp versions use 
blocking HTTP calls and thus run on their own native threads, while the 
emscripten version uses asynchronous calls on the main thread (and success 
and failure is communicated through callbacks). In order to 'tick' the 
XmlHttpRequests created by the emscripten version you need to give control 
back to the browser, and the success or failure callbacks will 'arrive' in 
a later frame (I'm thinking in 'frames' since the code that uses this is a 
3D engine).

Cheers,
-Floh.

Am Donnerstag, 18. August 2016 20:49:24 UTC+2 schrieb Sander Boer:
>
> Hi,
>
> for the life of me I cannot get the emscripten_wget of 
> emscripten_async_wget to work.
> I want to use wget to dl a json file I want to parse later, for this I 
> want to set up a temp file, dl the date, parse and destroy.
>
> However, it complains that the "file exists" of the FS in case of mounting 
> the MEMFS, or the size is 0 in case of FS.createDataFile..
>
> Help is appreciated.
>
>
> this is a snippet of the code I have:
> void Test2(){
>
>   EM_ASM(
>       // FS.mkdir('/');
>       // FS.mount(MEMFS, {}, '/');
>       FS.createDataFile("/", "file.txt", "File contents here", true, true);
>          );
>
>   char *path = "/file.txt";
>
>   printf("Downloading...\n");
>   myurl="http://test.site/json";;
>
>   // emscripten_async_wget(myurl.c_str(), path, onLoadWget, onErrorWget);
>   emscripten_wget(myurl.c_str(), path );
>
>   printf("Download completed\n");
>
>   FILE *json;
>   json=fopen(path,"r");
>   if(json==NULL) {
>     printf("ERROR: Can't open file!\n");
>     exit (2);
>   }else{
>     long size = ftell (json);
>     printf("size: %ld\n", size);
>     fputs ("fopen example\n", json);
>     fclose ( json );
>     }
>   }
>
> void onLoadWget(const char* fname){
>   printf("wget loaded: %s\n", fname);
>  }
>
> void onErrorWget(const char* fname){
>   printf("wget failed: %s", fname);
> }
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to