Skip to content

Commit

Permalink
Fix invalid CURL handle issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pschlan committed Feb 1, 2017
1 parent 283d22c commit 80ee7f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion chronos/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void App::processJobs(int hour, int minute, int month, int mday, int wday, int y
MYSQL_ROW row;
while((row = res->fetchRow()) != nullptr)
{
HTTPRequest *req = HTTPRequest::fromURL(row[0], atoi(row[10]), wt);
HTTPRequest *req = HTTPRequest::fromURL(row[0], atoi(row[10]));
req->result->jobID = atoi(row[1]);
req->result->datePlanned = (uint64_t)timestamp * 1000;
req->result->notifyFailure = strcmp(row[5], "1") == 0;
Expand Down
13 changes: 7 additions & 6 deletions chronos/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ size_t curlHeaderFunction(char *buffer, size_t size, size_t nitems, void *userda

}

HTTPRequest::HTTPRequest(CURLM *curlMultiHandle)
: multiHandle{curlMultiHandle},
result{std::make_unique<JobResult>()}
HTTPRequest::HTTPRequest()
: result{std::make_unique<JobResult>()}
{
maxSize = App::getInstance()->config->getInt("request_max_size");
memset(curlError, 0, sizeof(curlError));
Expand Down Expand Up @@ -177,8 +176,10 @@ void HTTPRequest::done(CURLcode res)
onDone();
}

void HTTPRequest::submit()
void HTTPRequest::submit(CURLM *curlMultiHandle)
{
multiHandle = curlMultiHandle;

result->dateStarted = Utils::getTimestampMS();
result->jitter = result->dateStarted - result->datePlanned;

Expand Down Expand Up @@ -234,9 +235,9 @@ void HTTPRequest::submit()
}
}

HTTPRequest *HTTPRequest::fromURL(const std::string &url, int userID, const std::shared_ptr<WorkerThread> &wt)
HTTPRequest *HTTPRequest::fromURL(const std::string &url, int userID)
{
HTTPRequest *req = new HTTPRequest(wt->curlHandle);
HTTPRequest *req = new HTTPRequest();
req->result->userID = userID;
req->result->url = url;
req->url = url;
Expand Down
6 changes: 3 additions & 3 deletions chronos/HTTPRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Chronos
class HTTPRequest
{
private:
HTTPRequest(CURLM *curlMultiHandle);
HTTPRequest();

HTTPRequest(const HTTPRequest &other) = delete;
HTTPRequest(HTTPRequest &&other) = delete;
Expand All @@ -37,9 +37,9 @@ namespace Chronos
~HTTPRequest();

public:
static HTTPRequest *fromURL(const std::string &url, int userID, const std::shared_ptr<WorkerThread> &wt);
static HTTPRequest *fromURL(const std::string &url, int userID);

void submit();
void submit(CURLM *curlMultiHandle);
void done(CURLcode res);

bool processData(const std::string &headers);
Expand Down
2 changes: 1 addition & 1 deletion chronos/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void WorkerThread::runJobs()
++runningJobs;

job->onDone = std::bind(&WorkerThread::jobDone, this, job);
job->submit();
job->submit(curlHandle);
}
}

Expand Down

0 comments on commit 80ee7f7

Please sign in to comment.