mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-11 13:30:01 -04:00
fix random segfaults
This commit is contained in:
parent
1bce63801d
commit
1ad301b26c
3 changed files with 31 additions and 12 deletions
|
@ -1,5 +1,8 @@
|
|||
# Libcurl.js Changelog:
|
||||
|
||||
## v0.6.6 (3/20/24):
|
||||
- Fix random segfaults due to an improper invocation of libcurl
|
||||
|
||||
## v0.6.5 (3/20/24):
|
||||
- Update Wisp client and server
|
||||
- Compile WolfSSL with greater site support
|
||||
|
|
|
@ -51,6 +51,7 @@ if [[ "$*" == *"release"* ]]; then
|
|||
echo "note: building with release optimizations"
|
||||
else
|
||||
COMPILER_OPTIONS="$COMPILER_OPTIONS --profiling -g"
|
||||
EMSCRIPTEN_OPTIONS="$EMSCRIPTEN_OPTIONS -sSTACK_OVERFLOW_CHECK=2 -sSAFE_HEAP=1"
|
||||
fi
|
||||
|
||||
if [[ "$*" == *"single_file"* ]]; then
|
||||
|
|
|
@ -7,6 +7,7 @@ class CurlSession {
|
|||
this.active_requests = 0;
|
||||
this.event_loop = null;
|
||||
this.requests_list = [];
|
||||
this.to_remove = [];
|
||||
}
|
||||
|
||||
assert_ready() {
|
||||
|
@ -54,16 +55,20 @@ class CurlSession {
|
|||
return request_ptr;
|
||||
}
|
||||
|
||||
remove_request(request_ptr) {
|
||||
this.assert_ready();
|
||||
remove_request_now(request_ptr) {
|
||||
_session_remove_request(this.session_ptr, request_ptr);
|
||||
|
||||
let request_index = this.requests_list.indexOf(request_ptr);
|
||||
if (request_index !== -1) {
|
||||
this.requests_list.splice(request_index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//remove the request on the next iteration of the loop
|
||||
remove_request(request_ptr) {
|
||||
this.assert_ready();
|
||||
this.to_remove.push(request_ptr);
|
||||
}
|
||||
|
||||
start_request(request_ptr) {
|
||||
this.assert_ready();
|
||||
_session_add_request(this.session_ptr, request_ptr);
|
||||
|
@ -77,21 +82,31 @@ class CurlSession {
|
|||
}
|
||||
|
||||
this.event_loop = setInterval(() => {
|
||||
let libcurl_active = _session_get_active(this.session_ptr);
|
||||
if (libcurl_active || this.active_requests) {
|
||||
_session_perform(this.session_ptr);
|
||||
}
|
||||
else {
|
||||
clearInterval(this.event_loop);
|
||||
this.event_loop = null;
|
||||
}
|
||||
this.event_loop_func();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
event_loop_func() {
|
||||
let libcurl_active = _session_get_active(this.session_ptr);
|
||||
if (libcurl_active || this.active_requests || this.to_remove) {
|
||||
if (this.to_remove.length) {
|
||||
for (let request_ptr of this.to_remove) {
|
||||
this.remove_request_now(request_ptr);
|
||||
}
|
||||
this.to_remove = [];
|
||||
}
|
||||
_session_perform(this.session_ptr);
|
||||
}
|
||||
else {
|
||||
clearInterval(this.event_loop);
|
||||
this.event_loop = null;
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this.assert_ready();
|
||||
for (let request_ptr of this.requests_list) {
|
||||
this.remove_request(request_ptr);
|
||||
this.remove_request_now(request_ptr);
|
||||
}
|
||||
_session_cleanup(this.session_ptr);
|
||||
this.session_ptr = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue