Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
salcock committed May 10, 2019
2 parents 6b929ae + 6363016 commit ca7dc7e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
36 changes: 29 additions & 7 deletions lib/ior-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ static int fill_buffer(io_t *io) {
struct timeval to;
// the following is adaped from docs/examples/fopen.c
to.tv_sec = 10, to.tv_usec = 0; // 10 seconds
curl_multi_timeout(DATA(io)->multi, &curl_to);
if (curl_multi_timeout(DATA(io)->multi, &curl_to) != CURLM_OK) {
return -1;
}
if (curl_to >= 0) {
to.tv_sec = curl_to / 1000;
if (to.tv_sec > 1)
Expand All @@ -168,8 +170,10 @@ static int fill_buffer(io_t *io) {
FD_ZERO(&fdw);
FD_ZERO(&fde);

/* FIXME: check return code */
curl_multi_fdset(DATA(io)->multi, &fdr, &fdw, &fde, &maxfd);
if (curl_multi_fdset(DATA(io)->multi, &fdr, &fdw, &fde,
&maxfd) != CURLM_OK) {
return -1;
}
if (maxfd >= 0 &&
(rc = select(maxfd + 1, &fdr, &fdw, &fde, &to)) < 0)
break;
Expand All @@ -182,8 +186,10 @@ static int fill_buffer(io_t *io) {
nanosleep(&req, &rem);
}
curl_easy_pause(DATA(io)->curl, CURLPAUSE_CONT);
/* FIXME: check return code */
rc = curl_multi_perform(DATA(io)->multi, &n_running);
if (curl_multi_perform(DATA(io)->multi, &n_running) !=
CURLM_OK) {
return -1;
}
if (DATA(io)->total_length < 0) {
// update file length.
double cl;
Expand All @@ -195,6 +201,21 @@ static int fill_buffer(io_t *io) {
} while (n_running &&
DATA(io)->l_buf < DATA(io)->m_buf - CURL_MAX_WRITE_SIZE);

// check if there were any errors from curl
struct CURLMsg *m = NULL;
do {
int msgq = 0;
m = curl_multi_info_read(DATA(io)->multi, &msgq);
if (m != NULL && m->data.result != CURLE_OK) {
// there was an error reading -- if this is the first
// read, then the wandio_create call will fail.
fprintf(stderr, "HTTP ERROR: %s (%d)\n",
curl_easy_strerror(m->data.result),
m->data.result);
return -1;
}
} while (m != NULL);

if (DATA(io)->l_buf < DATA(io)->m_buf - CURL_MAX_WRITE_SIZE) {
if (DATA(io)->off0 + DATA(io)->p_buf >=
DATA(io)->total_length) {
Expand Down Expand Up @@ -272,9 +293,10 @@ io_t *init_io(io_t *io) {
curl_easy_setopt(DATA(io)->curl, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_WRITEFUNCTION, write_cb);
curl_easy_setopt(DATA(io)->curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_SSL_VERIFYHOST, 1L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(DATA(io)->curl, CURLOPT_USERAGENT, "wandio/"PACKAGE_VERSION);

/* for remote files, the buffer set to 2*CURL_MAX_WRITE_SIZE */
DATA(io)->m_buf = CURL_MAX_WRITE_SIZE * 2;
Expand Down
4 changes: 3 additions & 1 deletion tools/wandiocat/wcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int main(int argc, char *argv[]) {
iow_t *iow = wandio_wcreate(output, compress_type, compress_level, 0);
/* stdout */
int i;
int rc = 0;

#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
if (posix_memalign((void **)&buffer, 4096, WANDIO_BUFFER_SIZE) != 0) {
Expand All @@ -117,6 +118,7 @@ int main(int argc, char *argv[]) {
io_t *ior = wandio_create(argv[i]);
if (!ior) {
fprintf(stderr, "Failed to open %s\n", argv[i]);
rc++;
continue;
}

Expand All @@ -131,5 +133,5 @@ int main(int argc, char *argv[]) {
}
free(buffer);
wandio_wdestroy(iow);
return 0;
return rc;
}

0 comments on commit ca7dc7e

Please sign in to comment.