testing curl for android

This commit is contained in:
2017-03-28 09:19:25 +01:00
parent 2024b3a280
commit 291ba7ae78
3 changed files with 38 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ target_include_directories(native-lib PRIVATE
../libs/tinyxml2
../libs/yoga
../libs/stb
../libs/curl/android/include
)
# add lib dependencies
@@ -53,7 +54,9 @@ target_link_libraries(
native-lib
android
app-glue
${CMAKE_SOURCE_DIR}/../libs/curl/android/armeabi-v7a/libcurl.a
EGL
GLESv3
log
z
)

View File

@@ -3,6 +3,7 @@
package="com.omigamedev"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="false"

View File

@@ -289,12 +289,46 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
* android_native_app_glue. It runs in its own thread, with its own
* event loop for receiving input events and doing other things.
*/
#include <curl/curl.h>
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
LOG("READ SOMETHIND");
return size * nmemb;
}
int curl_test()
{
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
LOG("READ: %s", readBuffer.c_str());
}
else
{
LOG("READ FAILED");
}
return 0;
}
void android_main(struct android_app* state) {
struct engine engine;
// Make sure glue isn't stripped.
app_dummy();
LOG("NETWORK TESTING...");
curl_test();
LOG("NETWORK TESTED");
memset(&engine, 0, sizeof(engine));
state->userData = &engine;
state->onAppCmd = engine_handle_cmd;