Skip to content

Conversation

@shishirb-MSFT
Copy link
Collaborator

No description provided.

@shishirb-MSFT shishirb-MSFT requested a review from a team as a code owner September 2, 2021 00:22
#include <curl/curl.h>
#include "do_event.h"

class CurlMultiOperation
Copy link
Collaborator Author

@shishirb-MSFT shishirb-MSFT Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CurlMultiOperation

I might do some refactoring and add comments in another PR. Let me know if you have any questions here. #Resolved


====================================================================

microsoft/cpprestsdk 18212a2a7967e12d740bfb957e500892b3463c88 - MIT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpprestsdk

I'll follow up with Carmen about adding libcurl info here and in cgmanifest.

#include "do_common.h"
#include "download.h"

#include <cmath>
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this unused? #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used for std::round on line 455. I think it was being brought in by one of cpprest's headers earlier.


# Open-source library dependencies
# Boost libs for DO
# Boost libs
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just delete this comment now. Before it was to distinguish which were used for DO and which were used for cpprest #Closed

_requestContext.hrTranslatedStatusCode = S_OK;
_requestContext.responseOnHeadersAvailableInvoked = false;
_requestContext.responseOnCompleteInvoked = false;
_callbackContext = callerContext;
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callerContext;

Do we need to expose this as a function param? Looks like it's never set and default value is always used. It looks like a param for the IHttpEvents interface but unused by the functions implementing that interface #WontFix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove in the next PR.

DoLogVerbose("New http_client for %s", szUrl);

// Set options that are generic to all requests
curl_easy_setopt(_requestContext.curlHandle, CURLOPT_FOLLOWLOCATION, static_cast<long>(1));
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl_easy_setopt(_requestContext.curlHandle, CURLOPT_FOLLOWLOCATION, static_cast(1));

Maybe I misunderstood but you mentioned in sync 302'ing urls needed manual handling? Doesn't this take care of redirects? #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make libcurl follow the redirect automatically but we still get headers back for the 302 response before getting headers for the 200.


// Set options that are generic to all requests
curl_easy_setopt(_requestContext.curlHandle, CURLOPT_FOLLOWLOCATION, static_cast<long>(1));
curl_easy_setopt(_requestContext.curlHandle, CURLOPT_MAXREDIRS, static_cast<long>(10));
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10

-1 allows infinite redericts, 10 to avoid infinite redirecting (can such a thing happen?) #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It can happen so we limit it.

Copy link
Contributor

@jimson-msft jimson-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:


ConfigManager clientConfigs;
auto downloadManager = std::make_shared<DownloadManager>(clientConfigs);
CurlMultiOperation curlOperations;
Copy link
Collaborator Author

@shishirb-MSFT shishirb-MSFT Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curlOperations

Move this to DownloadManager. #Resolved

}
}

void CurlMultiOperation::_WorkerThread()
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming this to _DoWork() #Resolved


if (_activeHandles.Empty())
{
_cv.wait(lock, [this](){ return !_fKeepRunning || !_handlesToAdd.empty(); });
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!_handlesToAdd.empty()

if this is non-empty, wouldn't cv wait here forever? There's no way to drain/clear the vector except for line 89 right? for example if AddHandle() is called while this thread is executing between line 89 and 99 - wouldn't this e stuck unless fkeepRunning gets set to false? #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the opposite - wait() will return if _handlesToAdd becomes non-empty or _fKeepRunning becomes false.

Also note that AddHandle will wait if we were executing line 89-99 at that time (same mutex).

DO_ASSERT(false); // TODO(shishirb) how to handle?
break;

case 0:
Copy link
Contributor

@jimson-msft jimson-msft Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have mentioned this when we went over this, but for case 0: it indicates the process timed out? Should a comment be added on why we leave this case empty? #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 = timeout, yes. Note this case isn't empty but falls through to call curl_multi_perform. I've added some comments in the next iteration.

@shishirb-MSFT shishirb-MSFT merged commit 70140de into feature/replace-cpprest Sep 7, 2021
@shishirb-MSFT shishirb-MSFT deleted the user/shishirb/ni-use-libcurl branch September 7, 2021 18:58
shishirb-MSFT added a commit that referenced this pull request Sep 16, 2021
* Agent now uses the curl lib with the multi interface with the select model of doing work.
* Agent: Explicit link to pthread lib (cpprest was doing it on our behalf).
* DownloadManagerTests: use polling, temporarily increase wait time
* Add libcurl to bootstrap. Remove cpprest.
shishirb-MSFT added a commit that referenced this pull request Sep 16, 2021
* Agent now uses the curl lib with the multi interface with the select model of doing work.
* Agent: Explicit link to pthread lib (cpprest was doing it on our behalf).
* DownloadManagerTests: use polling, temporarily increase wait time
* Add libcurl to bootstrap. Remove cpprest.
shishirb-MSFT added a commit that referenced this pull request Sep 16, 2021
* Agent now uses the curl lib with the multi interface with the select model of doing work.
* Agent: Explicit link to pthread lib (cpprest was doing it on our behalf).
* DownloadManagerTests: use polling, temporarily increase wait time
* Add libcurl to bootstrap. Remove cpprest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants