So i was just integrating libcurl into one of my projects and decided to test it by running a simple libcurl script that connects to my website, checks and compares numbers. The problem is, every time i run it i cant move my mouse or get keyboard input until libcurl is done connecting. I would like it to run at the same time and the only way i see that is by putting it on its own thread and have two of them but wanted to see if you had any suggestions.
Basically i have a button when pressed connects copy webpage to a string (which is a simple number) and than outputs it to my editbox. im using mygui and when i click this button i cant move mouse or get keyboard input until libcurl is done.
Libcurl and ogre
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Libcurl and ogre
AFAIK the easy interface just blocks. You need to bump up to the multi interface. Also there should be examples in the source docs. If you still have questions after checking that out, you should join the mailing list.
-
- Halfling
- Posts: 41
- Joined: Tue Dec 24, 2013 1:38 am
Re: Libcurl and ogre
Yeah so i have been looking at the multi interface and it should work. I have joined the mailing list but your first question is moderated and nobody has accepted it yet so...I am asking here.
So as a test this was my original code and worked
Now i have tried changing this so i uses the multi interface but it keeps coming back Doesn't work while the one posted above worked.
I also find it hard to error check because it uses printf and i don't know how to use that with the ogre log or mygui to edit box. and i have been going over the examples but cant seem to find anything that would cause that (I may be overlooking to me the code is confusing a little).
So as a test this was my original code and worked
Code: Select all
CURL *curl;
string response;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "myurl");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
string test = "1.0.0";
if (response == test)
{
edbMain->addText("Works");
}
else
{
edbMain->addText("Doesn't Work");
}
}
Code: Select all
CURL *curl;
CURLM *mcurl;
int still_running;
string response;
curl = curl_easy_init();
mcurl = curl_multi_init();
if(curl && mcurl)
{
curl_easy_setopt(curl, CURLOPT_URL, "myurl");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_multi_add_handle(mcurl, curl);
curl_multi_perform(mcurl, &still_running);
/* always cleanup */
curl_multi_cleanup(mcurl);
curl_easy_cleanup(curl);
string test = "1.0.0";
if (response == test)
{
edbMain->addText("Works");
}
else
{
edbMain->addText("Doesn't work");
}
}
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Libcurl and ogre
Not sure what to say when libcurl ships with so many examples. Instead of trying to nonblock with the multi interface, you could just use the easy interface in a background thread. You just can't block for I/O in the render / input thread ... or else rendering and input will have to wait for libcurl to finish before being processed.
-
- Halfling
- Posts: 41
- Joined: Tue Dec 24, 2013 1:38 am
Re: Libcurl and ogre
Okay so i have libcurl working in another thread just fine but i have noticed a problem that is not related to it at all. Im posting here because i feel like its a simple problem. So to exit my application you can press esc temporarily but i have a button to that closes the app the same way as esc does. Pretty much in the frameRenderingQueued function i just return false if its true like so . This works on debug with no problems but on release the application closes but than the windows dialog box pops up saying the application has stopped responding. Any ideas on how to fix this
Code: Select all
if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
return false;
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Libcurl and ogre
You are shutting down the background thread and joining it in the main thread? You can use something simple like a global atomic bool to indicate app shutdown, which threads check to see if they should continue running.
-
- Halfling
- Posts: 41
- Joined: Tue Dec 24, 2013 1:38 am
Re: Libcurl and ogre
well i create a thread when a the update button is pressed and i dont join it to the main thread because than i will have to wait for it just like i had to before. And i dont know how to stop a boost thread i thought they just terminated when it was done since there was nothing about stopping them when i looked. btw im using boost version 1.55.0
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Libcurl and ogre
If you aren't looping in the thread then yes it should terminate when it runs out of instructions and you don't have to join it while shutting down. Perhaps the problem you are having is unrelated to threading, it's hard to say.