emscripten获取始终返回0
Emscripten Fetch always return 0
我遵循emscripten随附的同步提取示例如下;
void main()
{
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_SYNCHRONOUS;
emscripten_fetch_t *fetch = emscripten_fetch(&attr, "https://ichef.bbci.co.uk/news/660/cpsprodpb/E9DF/production/_96317895_gettyimages-164067218.jpg");
printf("Fetch finished with status %dn", fetch->status);
}
它总是从获取状态返回0
i用
编译FLAGS += -std=c++17 -stdlib=libc++ -O3
FLAGS += -s WASM=1 -s USE_WEBGL2=1 -s FULL_ES3=1
FLAGS += -s ALLOW_MEMORY_GROWTH=1
FLAGS += -o hello.html
FLAGS += -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']"
FLAGS += --no-heap-copy
FLAGS += -s FETCH=1
但是,当我使用异步测试并读取OnSuccess函数中的数据时。数据打印正确
static
void ondownload_success(emscripten_fetch_t *fetch)
{
printf("[ download ][ OK ] %llu bytes [ URL ]: %sn", fetch->numBytes, fetch->url);
printf("%c %c %c", fetch->data[0], fetch->data[3], fetch->data[2] );
emscripten_fetch_close(fetch); // Free data associated with the fetch.
}
我的获取同步代码有什么问题?一切都与" example_synchronous_fetch.cpp" example
完全相同我在Windows10上运行。Emscripten 1.38.29。使用Microsoft Edge无需服务器即可直接浏览文件(双击Hello.html)
同步fetch
有一些额外的限制,似乎您的构建标志不启用同步fetch
:
同步emscripten提取操作受到许多限制,具体取决于哪种emscripten构建模式(链接标志)使用:
无标志:只有异步提取操作。
–proxy-to-worker:仅进行XHR但不与indexedDB相互作用的获取允许同步提取操作。
-s use_pthreads = 1:同步提取操作可在pthreads上获得,但在主线程上不可用。
- proxy-to-worker -s use_pthreads = 1:同步提取操作在主线程和pthreads上都可用。
https://emscripten.org/docs/api_reference/fetch.html#synchronous-fetches
相关文章:
- 如何获取std::result_of函数的返回类型
- 从python中调用C++函数并获取返回值
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 调用CreateProcess()并获取字符串的返回值
- C++ - 声明指向返回任何类型并获取任意数量参数的函数的指针
- C++ 获取函数在常量引用中按值返回的结果
- 从返回 std::optional of std::vector 的函数中获取结果到调用方
- 为什么在分配给成员变量之前获取unique_ptr的返回是一个问题?
- 函数从指针 c++ 中获取错误的值并返回错误的答案
- 如何将不可移动和不可复制的函数返回值获取到数组中
- 在 c++ 中从执行的 shell 命令获取返回状态的安全方法是什么?
- 获取上次执行的返回语句的行
- 如何在C++中执行命令并获取命令的返回代码标准输出和标准
- 如何使用 std::invoke_result_t 获取函数的返回类型
- 如何在 c++ 窗口中将参数和返回的退出值传递到批处理文件/从批处理文件获取返回的退出值
- 获取进程标识符始终返回 0
- 如何在C++中从Lua函数获取返回表?
- 获取模板函数/泛型 lambda 的唯一返回类型
- Cocos2d-x TiledMap,在调用 getLayer() 获取碰撞层时返回一个 nullptr?
- C++日历(无法获取变量的值以返回到主函数)