Skip to content

Commit

Permalink
Re-throw interrupts (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen authored Dec 21, 2024
1 parent 0ae1b44 commit 8ca658f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: curl
Type: Package
Title: A Modern and Flexible Web Client for R
Version: 6.0.2
Version: 6.1.0
Authors@R: c(
person("Jeroen", "Ooms", role = c("aut", "cre"), email = "jeroenooms@gmail.com",
comment = c(ORCID = "0000-0002-4035-0289")),
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
6.0.2
6.1.0
- Fix a rchk bug
- Enable CURLOPT_PIPEWAIT by default to prefer multiplex when possible
- Enable setting max_streams in multi_set(), default to 10
- Allow open(curl::curl()) to be interrupted

6.0.1
- Fix a build issue with libcurl 8.11.0
Expand Down
4 changes: 4 additions & 0 deletions src/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ static Rboolean rcurl_open(Rconnection con) {
while(block_open && req->has_more && !req->has_data) {
int numfds;
massert(curl_multi_wait(req->manager, NULL, 0, 1000, &numfds));
if(pending_interrupt()) {
reset(con); //cleanup before jumping
assert_message(CURLE_ABORTED_BY_CALLBACK, NULL);
}
massert(curl_multi_perform(req->manager, &(req->has_more)));
for(int msg = 1; msg > 0;){
CURLMsg *out = curl_multi_info_read(req->manager, &msg);
Expand Down
17 changes: 17 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#include "curl-common.h"
#include <stdint.h> /* SIZE_MAX */

#ifdef _WIN32
#include <Rembedded.h>
void send_r_interrupt() {
UserBreak = 1;
R_CheckUserInterrupt();
}
#else
#include <Rinterface.h>
void send_r_interrupt() {
Rf_onintr();
}
#endif

CURL* get_handle(SEXP ptr){
return get_ref(ptr)->handle;
}
Expand Down Expand Up @@ -40,6 +53,8 @@ void reset_errbuf(reference *ref){
void assert_message(CURLcode res, const char *str){
if(res == CURLE_OK)
return;
if(res == CURLE_ABORTED_BY_CALLBACK)
send_r_interrupt();
if(str == NULL)
str = curl_easy_strerror(res);
SEXP code = PROTECT(Rf_ScalarInteger(res));
Expand All @@ -54,6 +69,8 @@ void assert_message(CURLcode res, const char *str){
void assert_status(CURLcode res, reference *ref){
if(res == CURLE_OK)
return;
if(res == CURLE_ABORTED_BY_CALLBACK)
send_r_interrupt();
const char *source_url = NULL;
curl_easy_getinfo(ref->handle, CURLINFO_EFFECTIVE_URL, &source_url);
SEXP url = PROTECT(make_string(source_url));
Expand Down

0 comments on commit 8ca658f

Please sign in to comment.