Skip to content

Commit

Permalink
Get error code on failure to load file for emscripten httpfs (#316)
Browse files Browse the repository at this point in the history
...uses emscripten_wget2 function to get an actual error code back from failed HTTP requests
  • Loading branch information
pixelherodev authored and floooh committed Oct 8, 2018
1 parent 535eab4 commit ad2fc30
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions code/Modules/HttpFS/private/emsc/emscURLLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ emscURLLoader::startRequest(const Ptr<IORead>& req) {
// start the asynchronous XHR
// NOTE: we can only load from our own HTTP server, so the host part of
// the URL is completely irrelevant...
String urlPath = req->Url.PathToEnd();
emscripten_async_wget_data(urlPath.AsCStr(), (void*) reqPtr, emscURLLoader::onLoaded, emscURLLoader::onFailed);
StringBuilder urlPath = "/";
urlPath.Append(req->Url.PathToEnd());
emscripten_async_wget2_data(urlPath.AsCStr(), "GET", NULL, (void*) reqPtr, true, emscURLLoader::onLoaded, emscURLLoader::onFailed, NULL);
}

//------------------------------------------------------------------------------
void
emscURLLoader::onLoaded(void* userData, void* buffer, int size) {
emscURLLoader::onLoaded(unsigned int handle, void* userData, void* buffer, unsigned int size) {
o_assert(0 != userData);
o_assert(0 != buffer);
o_assert(size > 0);
Expand All @@ -53,18 +54,15 @@ emscURLLoader::onLoaded(void* userData, void* buffer, int size) {

//------------------------------------------------------------------------------
void
emscURLLoader::onFailed(void* userData) {
emscURLLoader::onFailed(unsigned int handle, void* userData, int errorCode, const char *statusDescription) {
o_assert(0 != userData);

// user data is a HTTPRequest ptr, put it back into a smart pointer
Ptr<IORead> req((IORead*)userData);
req->release();
Log::Dbg("emscURLLoader::onFailed(url=%s)\n", req->Url.AsCStr());
Log::Dbg("emscURLLoader::onFailed(url=%s, code=%d, message=%s)\n", req->Url.AsCStr(), errorCode, statusDescription);

// hmm we don't know why it failed, so make something up, we should definitely
// fix this somehow (looks like the wget2 functions also pass a HTTP status code)
const IOStatus::Code ioStatus = IOStatus::NotFound;
req->Status = ioStatus;
req->Status = (IOStatus::Code)errorCode;
req->Handled = true;
}

Expand Down
4 changes: 2 additions & 2 deletions code/Modules/HttpFS/private/emsc/emscURLLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class emscURLLoader : public baseURLLoader {
/// start the next, called from doWork
void startRequest(const Ptr<IORead>& req);
/// success callback
static void onLoaded(void* userData, void* buffer, int size);
static void onLoaded(unsigned int handle, void* userData, void* buffer, unsigned int size);
/// failure callback
static void onFailed(void* userData);
static void onFailed(unsigned int handle, void* userData, int errorCode, const char *statusDescription);
};

} // namespace _priv
Expand Down

0 comments on commit ad2fc30

Please sign in to comment.