curl-easy | Supports parallel | Command Line Interface library
kandi X-RAY | curl-easy Summary
kandi X-RAY | curl-easy Summary
cURL wrapper for PHP. Supports parallel and non-blocking requests. For high speed crawling, see stil/curl-robot
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Read data from the pool
- Load CURL constants table
- Send the request
- Find the numeric value of a cURL option .
- Set a value in the template
- Apply options to the request .
- Perform socket operation .
- Get a specific key .
- Get default options
- Get error .
curl-easy Key Features
curl-easy Examples and Code Snippets
Community Discussions
Trending Discussions on curl-easy
QUESTION
I am trying to use curl in a C++ application I am developing using Visual Studio 2017. I like the idea of using Nuget because it is a very clean way of implementing a library. I tried to follow the example below from the Microsoft forum, which led me to use the “rmt_curl” package (linked below). This, however, left VS unable to find “curl.h”.
rmt_curl nuget package: https://www.nuget.org/packages/rmt_curl/
So I switched to use the “curl” package, which fixed the header file, but resulted in “unresolved external symbol” for each of the curl functions.
curl nuget package: https://www.nuget.org/packages/curl/
Inspired by other comments and answers I added “libcurl.lib” to the project “Properties->Linker->Input->Additional Dependencies” list. This results in “cannot open file ‘libcurl.lib’”.
After trying about half of the “libcurl.lib files in the “packages\curl.7.30.0.2” folder, I finally found one that compiled. I added “$(SolutionDir)\packages\curl.7.30.0.2\build\native\lib\v110\Win32\$(Configuration)\dynamic” to the project “Properties->Linker->General->Additional Library Directories” field.
Now the problem is that when running it, “LIBCURL.dll is not found”. This made realize that earlier I liked against the dynamic version of the .lib file. This is not what I want. I want to statically link the library and not bother with a DLL.
Here is the sample code I am trying to run before I try this in my real application:
...ANSWER
Answered 2019-Mar-07 at 00:12How to use curl Nuget package in C++ application
Since you are using the curl
package, you will notice that there are only two lib versions for Visual Studio: v100 & v110:
The curl
package should only work fine on Visual studio V100 and V110. I tested your sample code with the curl
package on Visual Studio 2010 and 2012, and it worked fine.
So this package is not compatible with VS 2015 & VS 2017 (VS 2017 uses toolset v141 and the package only supports v110 and v120). If you want to use this package on Visual Studio 2015 and 2017, you can change the toolset to a previous one. Go into Project Properties->General->Platform Toolset, and change it to Visual Studio 2010 (v100). (You will need to install the VS2010 or VS 2012) Test it and confirm it works fine.
If you don't want to install VS2010 or VS2012, you can try to use the rmt_curl package instead, but there are some points you need to pay attention to, otherwise you will not get it to work.
For VS2015, after you install the package rmt_curl
, you will notice that the curl.h
exists in the External Dependencies:
So just use #include
instead of #include
to include the header file. After using #include
, the project built fine in my Visual Studio 2015.
For Visual Studio 2017, rmt_curl
does not work, but you can change the toolset to Visual Studio 2015 (v140) (You'll Need install Microsoft Build Tools 2015 or VS 2015). It works for me.
Hope that this mess of answer doesn't bother you. It seems that the curl
package is not perfect, so we should pay more attention when using it so it can become more perfect.
Hope the above info can help you, and if you have any doubts about this solution, please let me know.
QUESTION
I use libcurl easy interface and I create lots of threads in my c++ app to handle these http requests. I would like to convert the code to use libcurl multi instead. Conceptually, the idea is clear: instead of calling blocking curl_easy_perform on each curl easy handle from multiple threads I'll call a blocking curl_multi_perform from a single thread and this call internally will handle all attached curl easy handles.
Things that aren't clear to me:
how do I cancel any of the outstanding http requests that are being handled by the blocking curl_multi_perform call (from another thread). Similarly, would the same work with easy interface, can I end/about an http request from another thread while there is another thread does curl_easy_perform on that handle.
Is it ok to add new easy handles to a multi handle while there is another thread calls curl_multi_perform on the multi handle?
If I use curl_multi_remove_handle to abort one of outgoing http requests while it was loading data (let's say it was doing 1GB file download) then I can reuse the same handle right after that. Does curl close that tcp connection that was aborted in the middle? Otherwise, I don't see how that connection could possibly be reused without completely downloading entire 1GB body.
Is there a simple example that used to do multiple easy requests from different threads and same example converted to multi interface?
...ANSWER
Answered 2018-Jan-26 at 08:30(This is really several questions disguised as one, which is not a good fit for stackoverflow.)
curl_multi_perform()
doesn't block. It does as much as it can do for now, then it returns and expects the program to call it again when it's time or when there's activity on one of its sockets.
Ideally you can mark which transfers to stop in the other threads and as soon as curl_multi_perform()
returns you can remove said easy handles from the multi handle and they're no longer in the game. Alternatively, you can use the individual transfer's callbacks (write/read/progress) to return error when you want that transfer to end.
It is not OK to use the same libcurl handle in more than one thread at any given moment. If you really need to use the same handle from more than one thread, then you need to do careful mutexing. See the libcurl treading man page. It is usually better to put things into qeueus from the other threads and let the single libcurl-using thread read handles or actions from that queue when it can, which then assures single thread access to the handles.
If you abort a transfer by removing the handle with curl_multi_remove_handle()
, that transfer is aborted. Stopped. You can indeed reuse that handle immediately and if you just put it back in, it will be treated as a brand new transfer and unless you change any options in the easy handle it will simply start off from the beginning again with the same URL. Prematurely aborted transfers will of course be treated correctly, which might include closing the TCP connection if necessary.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install curl-easy
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page