2012-04-19 14:35:52 +08:00
|
|
|
#include "CurlTest.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "curl/curl.h"
|
|
|
|
|
|
|
|
CurlTest::CurlTest()
|
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("Curl Test", "fonts/arial.ttf", 28);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(label, 0);
|
2014-05-15 01:07:09 +08:00
|
|
|
label->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y-50) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(CurlTest::onTouchesEnded, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create a label to display the tip string
|
2014-04-09 23:31:05 +08:00
|
|
|
_label = Label::createWithTTF("Touch the screen to connect", "fonts/arial.ttf", 22);
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setPosition(VisibleRect::center());
|
|
|
|
addChild(_label, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the test code is
|
|
|
|
// http://curl.haxx.se/mail/lib-2009-12/0071.html
|
2013-09-03 18:22:03 +08:00
|
|
|
void CurlTest::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
|
|
|
char buffer[10];
|
|
|
|
|
|
|
|
curl = curl_easy_init();
|
|
|
|
if (curl)
|
|
|
|
{
|
2014-07-02 10:18:07 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "baidu.com");
|
2012-04-19 14:35:52 +08:00
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
/* always cleanup */
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
if (res == 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setString("0 response");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(buffer,"code: %i",res);
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setString(buffer);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->setString("no curl");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurlTest::~CurlTest()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_label->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CurlTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new CurlTest();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|