-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The asiohiper.cpp example code is not doing things quite right #1191
Comments
A request for help with exactly this example went out not too long ago so the fact it is not working correctly is known. We just haven't had anyone around with asio knowledge or experience to do it! We'll greatly appreciate your help! |
Fix the problem in asiohiper.cpp. libcurl requires CURLMOPT_SOCKETFUNCTION to KEEP watching socket events and notify back. Modify event_cb() to continue watching events when fired. [Bug: Fixes Issue curl#1191] [Fixed by: Mingliang Zhu]
A test result for the commit. The exec time seems reasonable now and the downloaded content is correct. $ time ./asiohiper real 0m3.941s $time ./asiohiper_mod real 0m0.667s |
@bagder I didn't notice those reports. I just read Issue 1170 and it looks like to be caused by the same problem. But the http request is a little more complicated. I'll take a close look if my commit fixes that. |
I further examined Issue #1170 and unfortunately it seems to be another problem than I have reported. |
No it isn't blocking at all (for most TLS backends at least) asio doesn't know about SSL so of course it has no particular knowledge or saying about the SSL handshake, it just gets socket activities and tells libcurl about them for SSL handshakes as well as any other socket stuff. |
It turns out that my problem get solved by switching libcurl to master. |
[ There are collections of known issues to be aware of:
https://curl.haxx.se/docs/knownbugs.html https://curl.haxx.se/docs/todo.html ]
There is an example code demostrating curl multi working with boost::asio at docs/examples/asiohiper.cpp and also at https://curl.haxx.se/libcurl/c/asiohiper.html
When you try to run the code, the download progress is noticably slower than expected (compared with a program that uses just an easy interface), especially if you change the download url from google homepage into some larger pages. To make that more noticable, modify this line in the code:
curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 3L);
Change "3L" to something larger, say 10L. Make that even larger may also cause a timeout or failure.
Even worse, if that line of code get commented out, the program will exit while only the beginning of page downloaded, and the "DONE: some_url => (0)" log line never got printed.
CURLOPT_LOW_SPEED_TIME
just controls low speed detection, and should never cause download progress to be slow or fail (provided the network connection is not really that slow).The problem is that the example uses
CURLMOPT_SOCKETFUNCTION
to connect libcurl toboost::asio
. libcurl requiresCURLMOPT_SOCKETFUNCTION
to KEEP watching socket events and notify back. The example usesasync_read_some()
andasync_write_some()
to watch socket events. However, those two functions are both one-time watcher, so once some event has been fired, those two funcitons should be called again to meet the "keep watching" requirement of libcurl.With the
CURLOPT_LOW_SPEED_TIME
removed, after first socket read event has fired, there will be no further things forboost::asio
to do, so the program exits immediatly, leaving the url only partly downloaded. WithCURLOPT_LOW_SPEED_TIME
set, there will be a timer left inboost::asio
for that, and that's why the the original code keeps slowly running but not exiting.I'll provide a PR trying to fix this later.
The text was updated successfully, but these errors were encountered: