我无法将应用程序移植到asm.js.我们有一个为我们处理HTTP GET的类,我试图使用emscripten_fetch api进行移植。
我只能在异步提取工作,并且只有在主线程上调用时才能工作。使用来自https://kripken.github.io/emscripten-site/docs/api_reference/fetch.html的示例代码,我构建了它。
// 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);
}
我正在使用以下方式构建它:
emcc main.cpp -o $(OUTPUT_FOLDER)/thread_test.html -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=5 -s FETCH=1
我的错误&#39;正在使用“获取 - >”状态调用方法&#39;如果我打电话给&#39; worker()&#39;方法直接我得到预期的行为。
我在这里撕扯我的头发。我用谷歌搜索了我能想到的一切无济于事。