Skip to content

Commit d079eca

Browse files
authored
Remove non-working emscripten_fetch_wait / EMSCRIPTEN_FETCH_WAITABLE. NFC (#22138)
This API hasn't worked since the fastcomp days, so I think its probably better to remove/deprecate it rather than try to make it work (perhaps using pthreads).
1 parent b963a9b commit d079eca

File tree

11 files changed

+9
-205
lines changed

11 files changed

+9
-205
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.62 (in development)
2222
-----------------------
23+
- The `EMSCRIPTEN_FETCH_WAITABLE` flag along with the `emscripten_fetch_wait`
24+
API were marked a deprecated. These feature have not functions for several
25+
years now. (#22138)
2326
- The internal `read_` function was removed. We now just use `readBinary` or
2427
`readAsync`. (#22080)
2528
- reference-types feature is now enabled by default in Emscripten, due to the

site/source/docs/api_reference/fetch.rst

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -200,55 +200,8 @@ emscripten_fetch() returns.
200200
- ``--proxy-to-worker`` + ``-pthread``: Synchronous Synchronous Fetch operations
201201
are available both on the main thread and pthreads.
202202

203-
Waitable Fetches
204-
================
205-
206-
Emscripten Fetch operations can also run in a third mode, called a *waitable*
207-
fetch. Waitable fetches start off as asynchronous, but at any point after the
208-
fetch has started, the calling thread can issue a wait operation to either wait
209-
for the completion of the fetch, or to just poll whether the fetch operation has
210-
yet completed. The following code sample illustrates how this works.
211-
212-
.. code-block:: cpp
213-
214-
int main() {
215-
emscripten_fetch_attr_t attr;
216-
emscripten_fetch_attr_init(&attr);
217-
strcpy(attr.requestMethod, "GET");
218-
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_WAITABLE;
219-
emscripten_fetch_t *fetch = emscripten_fetch(&attr, "file.dat"); // Starts as asynchronous.
220-
221-
EMSCRIPTEN_RESULT ret = EMSCRIPTEN_RESULT_TIMED_OUT;
222-
while(ret == EMSCRIPTEN_RESULT_TIMED_OUT) {
223-
/* possibly do some other work; */
224-
ret = emscripten_fetch_wait(fetch, 0/*milliseconds to wait, 0 to just poll, INFINITY=wait until completion*/);
225-
}
226-
// The operation has finished, safe to examine the fields of the 'fetch' pointer now.
227-
228-
if (fetch->status == 200) {
229-
printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url);
230-
// The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1];
231-
} else {
232-
printf("Downloading %s failed, HTTP failure status code: %d.\n", fetch->url, fetch->status);
233-
}
234-
emscripten_fetch_close(fetch);
235-
}
236-
237-
Waitable fetches allow interleaving multiple tasks in one thread so that the
238-
issuing thread can perform some other work until the fetch completes.
239-
240-
.. note::
241-
242-
Waitable fetches are available only in certain build modes:
243-
244-
- **No flags** or ``--proxy-to-worker``: Waitable fetches are not available.
245-
- ``-pthread``: Waitable fetches are available on pthreads, but not
246-
on the main thread.
247-
- ``--proxy-to-worker`` + ``-pthread``: Waitable fetches are
248-
available on all threads.
249-
250203
Tracking Progress
251-
====================
204+
=================
252205

253206
For robust fetch management, there are several fields available to track the
254207
status of an XHR.

src/generated_struct_info32.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,9 +1488,8 @@
14881488
"withCredentials": 60
14891489
},
14901490
"emscripten_fetch_t": {
1491-
"__attributes": 112,
1492-
"__proxyState": 108,
1493-
"__size__": 208,
1491+
"__attributes": 108,
1492+
"__size__": 200,
14941493
"data": 12,
14951494
"dataOffset": 24,
14961495
"id": 0,

src/generated_struct_info64.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,6 @@
14891489
},
14901490
"emscripten_fetch_t": {
14911491
"__attributes": 128,
1492-
"__proxyState": 124,
14931492
"__size__": 272,
14941493
"data": 24,
14951494
"dataOffset": 40,

src/struct_info.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,6 @@
11011101
"readyState",
11021102
"status",
11031103
"statusText",
1104-
"__proxyState",
11051104
"__attributes"
11061105
]
11071106
},

system/include/emscripten/fetch.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ extern "C" {
6161
// emscripten_fetch() while the operation is in progress.
6262
#define EMSCRIPTEN_FETCH_SYNCHRONOUS 64
6363

64-
// If specified, it will be possible to call emscripten_fetch_wait() on the
65-
// fetch to test or wait for its completion.
6664
#define EMSCRIPTEN_FETCH_WAITABLE 128
65+
#pragma clang deprecated(EMSCRIPTEN_FETCH_WAITABLE, "waitable fetch requests are no longer implemented")
6766

6867
struct emscripten_fetch_t;
6968

@@ -190,8 +189,6 @@ typedef struct emscripten_fetch_t {
190189
// Specifies a human-readable form of the status code.
191190
char statusText[64];
192191

193-
_Atomic uint32_t __proxyState;
194-
195192
// For internal use only.
196193
emscripten_fetch_attr_t __attributes;
197194
} emscripten_fetch_t;
@@ -204,14 +201,7 @@ void emscripten_fetch_attr_init(emscripten_fetch_attr_t * _Nonnull fetch_attr);
204201
// given URL or from IndexedDB database.
205202
emscripten_fetch_t *emscripten_fetch(emscripten_fetch_attr_t * _Nonnull fetch_attr, const char * _Nonnull url);
206203

207-
// Synchronously blocks to wait for the given fetch operation to complete. This
208-
// operation is not allowed in the main browser thread, in which case it will
209-
// return EMSCRIPTEN_RESULT_NOT_SUPPORTED. Pass timeoutMSecs=infinite to wait
210-
// indefinitely. If the wait times out, the return value will be
211-
// EMSCRIPTEN_RESULT_TIMED_OUT.
212-
// The onsuccess()/onerror()/onprogress() handlers will be called in the calling
213-
// thread from within this function before this function returns.
214-
EMSCRIPTEN_RESULT emscripten_fetch_wait(emscripten_fetch_t * _Nonnull fetch, double timeoutMSecs);
204+
EMSCRIPTEN_RESULT emscripten_fetch_wait(emscripten_fetch_t * _Nonnull fetch, double timeoutMSecs) __attribute__((deprecated));
215205

216206
// Closes a finished or an executing fetch operation and frees up all memory. If
217207
// the fetch operation was still executing, the onerror() handler will be called

system/lib/fetch/emscripten_fetch.c

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -147,67 +147,14 @@ emscripten_fetch_t* emscripten_fetch(emscripten_fetch_attr_t* fetch_attr, const
147147
}
148148

149149
EMSCRIPTEN_RESULT emscripten_fetch_wait(emscripten_fetch_t* fetch, double timeoutMsecs) {
150-
#if __EMSCRIPTEN_PTHREADS__
151-
if (!fetch) {
152-
return EMSCRIPTEN_RESULT_INVALID_PARAM;
153-
}
154-
uint32_t proxyState = fetch->__proxyState;
155-
if (proxyState == 2) {
156-
// already finished.
157-
return EMSCRIPTEN_RESULT_SUCCESS;
158-
}
159-
if (proxyState != 1) {
160-
// the fetch should be ongoing?
161-
return EMSCRIPTEN_RESULT_INVALID_PARAM;
162-
}
163-
#ifdef FETCH_DEBUG
164-
emscripten_dbg("fetch: emscripten_fetch_wait..");
165-
#endif
166-
if (timeoutMsecs <= 0) {
167-
return EMSCRIPTEN_RESULT_TIMED_OUT;
168-
}
169-
while (proxyState == 1 /*sent to proxy worker*/) {
170-
if (emscripten_is_main_browser_thread()) {
171-
emscripten_err("fetch: emscripten_fetch_wait failed: main thread cannot block to wait for long periods of time! Migrate the application to run in a worker to perform synchronous file IO, or switch to using asynchronous IO.");
172-
return EMSCRIPTEN_RESULT_FAILED;
173-
}
174-
int ret = emscripten_futex_wait(&fetch->__proxyState, proxyState, timeoutMsecs);
175-
if (ret == -ETIMEDOUT) {
176-
return EMSCRIPTEN_RESULT_TIMED_OUT;
177-
}
178-
proxyState = fetch->__proxyState;
179-
}
180-
#ifdef FETCH_DEBUG
181-
emscripten_dbg("fetch: emscripten_fetch_wait done..");
182-
#endif
183-
184-
if (proxyState != 2) {
185-
return EMSCRIPTEN_RESULT_FAILED;
186-
}
187-
return EMSCRIPTEN_RESULT_SUCCESS;
188-
#else
189-
if (fetch->readyState >= STATE_DONE) {
190-
return EMSCRIPTEN_RESULT_SUCCESS; // already finished.
191-
}
192-
if (timeoutMsecs == 0) {
193-
return EMSCRIPTEN_RESULT_TIMED_OUT /*Main thread testing completion with sleep=0msecs*/;
194-
} else {
195-
#ifdef FETCH_DEBUG
196-
emscripten_err("fetch: emscripten_fetch_wait() cannot stop to wait when building without pthreads!");
197-
#endif
198-
return EMSCRIPTEN_RESULT_FAILED /*Main thread cannot block to wait*/;
199-
}
200-
#endif
150+
return EMSCRIPTEN_RESULT_FAILED;
201151
}
202152

203153
EMSCRIPTEN_RESULT emscripten_fetch_close(emscripten_fetch_t* fetch) {
204154
if (!fetch) {
205155
return EMSCRIPTEN_RESULT_SUCCESS; // Closing null pointer is ok, same as with free().
206156
}
207157

208-
#if __EMSCRIPTEN_PTHREADS__
209-
fetch->__proxyState = 0;
210-
#endif
211158
// This function frees the fetch pointer so that it is invalid to access it anymore.
212159
// Use a few key fields as an integrity check that we are being passed a good pointer to a valid
213160
// fetch structure, which has not been yet closed. (double close is an error)

test/fetch/test_fetch_sync_in_main_thread.c

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/fetch/test_fetch_waitable.c

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/test_browser.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,12 +4657,6 @@ def test_fetch_sync_xhr_in_proxy_to_worker(self):
46574657
self.btest_exit('fetch/test_fetch_sync_xhr.cpp',
46584658
args=['-sFETCH_DEBUG', '-sFETCH', '--proxy-to-worker'])
46594659

4660-
# Tests waiting on EMSCRIPTEN_FETCH_WAITABLE request from a worker thread
4661-
@unittest.skip("emscripten_fetch_wait relies on an asm.js-based web worker")
4662-
def test_fetch_sync_fetch_in_main_thread(self):
4663-
shutil.copyfile(test_file('gears.png'), 'gears.png')
4664-
self.btest_exit('fetch/test_fetch_sync_in_main_thread.cpp', args=['-sFETCH_DEBUG', '-sFETCH', '-sWASM=0', '-pthread', '-sPROXY_TO_PTHREAD'])
4665-
46664660
@disabled('https://github.com/emscripten-core/emscripten/issues/16746')
46674661
def test_fetch_idb_store(self):
46684662
self.btest_exit('fetch/test_fetch_idb_store.cpp', args=['-pthread', '-sFETCH', '-sPROXY_TO_PTHREAD'])
@@ -4692,11 +4686,6 @@ def test_fetch_stream_async(self):
46924686
create_file('myfile.dat', 'hello world\n' * 1000)
46934687
self.btest_exit('fetch/test_fetch_stream_async.c', args=['-sFETCH'])
46944688

4695-
@disabled('waitable fetch operations were disabled when the fetch worker was removed')
4696-
def test_fetch_waitable(self):
4697-
create_file('myfile.dat', 'hello world\n' * 1000)
4698-
self.btest_exit('fetch/test_fetch_waitable.c', args=['-sFETCH'])
4699-
47004689
def test_fetch_persist(self):
47014690
create_file('myfile.dat', 'hello world\n')
47024691
self.btest_exit('fetch/test_fetch_persist.c', args=['-sFETCH'])

0 commit comments

Comments
 (0)