Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from measurement-kit/feature/no_unsigned
Browse files Browse the repository at this point in the history
Make sure we don't use unsigned numbers in the API
  • Loading branch information
bassosimone authored Oct 19, 2018
2 parents 2e03466 + fb1b9b6 commit a2884e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions libcurlx-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static void usage() {
std::clog << " --header <header> : add <header> to headers\n";
std::clog << " --post : use POST rather than GET\n";
std::clog << " --post-data <data> : send <data> as body\n";
std::clog << " --timeout <sec> : set timeout of <sec> seconds\n";
std::clog << std::endl;
// clang-format on
}
Expand Down Expand Up @@ -122,6 +123,12 @@ int main(int, char **argv) {
mk_curlx_request_add_header(req.get(), param.second.c_str());
} else if (param.first == "post-data") {
mk_curlx_request_set_body(req.get(), param.second.c_str());
} else if (param.first == "timeout") {
// Implementation note: since this is meant to be just a testing
// client, we don't bother with properly validating the number that
// is passed here and we just use atoi(). A really robust client
// SHOULD instead use strtonum().
mk_curlx_request_set_timeout(req.get(), atoi(param.second.c_str()));
} else {
std::clog << "fatal: unrecognized param: " << param.first << std::endl;
usage();
Expand Down
11 changes: 6 additions & 5 deletions libcurlx.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void mk_curlx_request_add_header(mk_curlx_request_t *req, const char *h);

void mk_curlx_request_set_body(mk_curlx_request_t *req, const char *b);

void mk_curlx_request_set_timeout(mk_curlx_request_t *req, unsigned timeout);
void mk_curlx_request_set_timeout(mk_curlx_request_t *req, int timeout);

void mk_curlx_request_set_proxy_url(mk_curlx_request_t *req, const char *u);

Expand Down Expand Up @@ -74,7 +74,7 @@ struct mk_curlx_response_deleter {
};

using mk_curlx_response_uptr = std::unique_ptr<mk_curlx_response_t,
mk_curlx_response_deleter>;
mk_curlx_response_deleter>;

#ifdef MK_CURLX_INLINE_IMPL

Expand All @@ -93,7 +93,7 @@ struct mk_curlx_request {
std::string url;
std::vector<std::string> headers;
std::string body;
unsigned timeout = 7;
int timeout = 30 /* seconds */;
std::string proxy_url;
bool follow_redir = false;
};
Expand Down Expand Up @@ -128,7 +128,7 @@ void mk_curlx_request_set_body(mk_curlx_request_t *req, const char *b) {
if (req != nullptr && b != nullptr) req->body = b;
}

void mk_curlx_request_set_timeout(mk_curlx_request_t *req, unsigned timeout) {
void mk_curlx_request_set_timeout(mk_curlx_request_t *req, int timeout) {
if (req != nullptr) req->timeout = timeout;
}

Expand Down Expand Up @@ -432,7 +432,8 @@ mk_curlx_response_t *mk_curlx_perform(const mk_curlx_request_t *req) {
res->logs += "curl_easy_setopt(CURLOPT_WRITEDATA) failed\n";
return res.release();
}
if ((res->error = MK_CURLX_EASY_SETOPT(handle.get(), CURLOPT_TIMEOUT,
if (req->timeout > 0 &&
(res->error = MK_CURLX_EASY_SETOPT(handle.get(), CURLOPT_TIMEOUT,
req->timeout)) != CURLE_OK) {
res->logs += "curl_easy_setopt(CURLOPT_TIMEOUT) failed\n";
return res.release();
Expand Down

0 comments on commit a2884e2

Please sign in to comment.