2015-04-10 2 views
1

im new to nacl. В моей заявке я использую собственный завиток. Я проверил скручивание через nacl-порт. im получает ошибку «Не удалось разрешить имя хоста».Не удалось разрешить хост Ошибка с curl на NACL

Любая помощь будет назначена.

Ниже приведен пример кода:

hello_tutorial.cc:

// Copyright (c) 2013 The Chromium Authors. All rights reserved. 
// Use of this source code is governed by a BSD-style license that can be 
// found in the LICENSE file. 

#include <unistd.h> 
#include <stdio.h> 
#include <sys/socket.h> 
#include <sys/ioctl.h> 
#include "nacl_io/nacl_io.h" 
#include "ppapi/cpp/instance.h" 
#include "ppapi/cpp/module.h" 
#include "ppapi/cpp/var.h" 
#include "ppapi/utility/completion_callback_factory.h" 
#include "ppapi/utility/threading/simple_thread.h" 
#include "curl/curl.h" 
namespace { 

// The expected string sent by the browser. 
const char* const kHelloString = "hello"; 
// The string sent back to the browser upon receipt of a message 
// containing "hello". 
const char* const kReplyString = "hello from NaCl"; 

} // namespace 

class HelloTutorialInstance : public pp::Instance { 
public: 
    explicit HelloTutorialInstance(PP_Instance instance) 
     : pp::Instance(instance), 
     callback_factory_(this), 
     file_thread_(this){} 
    virtual ~HelloTutorialInstance() {} 
    int download_progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { 
     fprintf(stderr, "### Progress : %f : %f : %f", dlnow/dltotal, dlnow, dltotal); 

     return 0; 
    } 

    int download_callback(char *buffer, size_t size, size_t nitems, void *outstream) { 
     static int downloadSize = 0; 
     downloadSize += (size * nitems); 
     fprintf(stderr, "SIZE : %d", downloadSize); 
     return nitems * size; 
    } 

    void curlTest(int32_t /* result */) 
    { 
     CURLM *multiCurlHandle = NULL; 
     CURL *curlHandle = NULL; 
     int res = curl_global_init(CURL_GLOBAL_ALL); 
     if (res == CURLE_OK) { 
      multiCurlHandle = curl_multi_init(); 
      curlHandle = curl_easy_init(); 
      curl_easy_setopt(curlHandle, CURLOPT_URL, "www.google.com"); 
      curl_easy_setopt(curlHandle, CURLOPT_VERBOSE, 1); 
      curl_easy_setopt(curlHandle, CURLOPT_NOPROGRESS, 0); 
      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSFUNCTION ,&HelloTutorialInstance::download_progress_callback); 
      curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, &HelloTutorialInstance::download_callback); 

      res = curl_easy_perform(curlHandle); 


      //curl_multi_add_handle(multiCurlHandle, curlHandle); 
      //curl_multi_perform(multiCurlHandle, &handle_count); 
      if (CURLE_OK != res) { 
       fprintf(stderr, "curl_easy_perform failed !!\nReason : %s", curl_easy_strerror((CURLcode)res)); 
      } 
     } } 

    virtual void HandleMessage(const pp::Var& var_message) { 
    // Ignore the message if it is not a string. 
    if (!var_message.is_string()) 
     return; 

    // Get the string message and compare it to "hello". 
    std::string message = var_message.AsString(); 
    if (message == kHelloString) { 
     // If it matches, send our response back to JavaScript. 
     pp::Var var_reply(kReplyString); 
     nacl_io_init_ppapi(pp::Instance::pp_instance(),pp::Module::Get()->get_browser_interface()); 
     file_thread_.Start(); 
     file_thread_.message_loop().PostWork(
        callback_factory_.NewCallback(&HelloTutorialInstance::curlTest)); 
     PostMessage(var_reply); 
    } 
    } 
private: 
    pp::CompletionCallbackFactory<HelloTutorialInstance> callback_factory_; 
    pp::SimpleThread file_thread_; 
}; 

class HelloTutorialModule : public pp::Module { 
public: 
    HelloTutorialModule() : pp::Module() {} 
    virtual ~HelloTutorialModule() {} 

    virtual pp::Instance* CreateInstance(PP_Instance instance) { 
    return new HelloTutorialInstance(instance); 
    } 
}; 

namespace pp { 

Module* CreateModule() { 
    return new HelloTutorialModule(); 
} 

} // namespace pp 

Makefile:

# Copyright (c) 2013 The Chromium Authors. All rights reserved. 
# Use of this source code is governed by a BSD-style license that can be 
# found in the LICENSE file. 

# GNU Makefile based on shared rules provided by the Native Client SDK. 
# See README.Makefiles for more details. 

VALID_TOOLCHAINS := pnacl newlib glibc 

NACL_SDK_ROOT ?= $(abspath $(CURDIR)/../..) 

TARGET = part2 


include $(NACL_SDK_ROOT)/tools/common.mk 

CHROME_ARGS += --allow-nacl-socket-api=localhost 

LIBS = ppapi_cpp ppapi pthread nacl_io curl ssl crypto stdc++ z glibc-compat 

CFLAGS = -Wall 
SOURCES = hello_tutorial.cc 

# Build rules generated by macros from common.mk: 

$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS)))) 

# The PNaCl workflow uses both an unstripped and finalized/stripped binary. 
# On NaCl, only produce a stripped binary for Release configs (not Debug). 
ifneq (,$(or $(findstring pnacl,$(TOOLCHAIN)),$(findstring Release,$(CONFIG)))) 
$(eval $(call LINK_RULE,$(TARGET)_unstripped,$(SOURCES),$(LIBS),$(DEPS))) 
$(eval $(call STRIP_RULE,$(TARGET),$(TARGET)_unstripped)) 
else 
$(eval $(call LINK_RULE,$(TARGET),$(SOURCES),$(LIBS),$(DEPS))) 
endif 

$(eval $(call NMF_RULE,$(TARGET),)) 

Исполнение в терминале:

part2$ NACL_SDK_ROOT=~/nacl_sdk/pepper_40 NACL_ARCH=x86_64 TOOLCHAIN=newlib make clean run 
~/nacl_sdk/pepper_40/tools/common.mk:495: Using chrome at: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome 
    CXX newlib/Release/hello_tutorial_x86_64.o 
    LINK newlib/Release/part2_unstripped_x86_64.nexe 
    VALIDATE newlib/Release/part2_unstripped_x86_64.nexe 
    STRIP newlib/Release/part2_x86_64.nexe 
    CREATE_NMF newlib/Release/part2.nmf 
python ~/nacl_sdk/pepper_40/tools/run.py -C ~/nacl_sdk/pepper_40/getting_started/part2 -P "index.html?tc=newlib&config=Release" \ 
     -- /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \ 
     --enable-nacl --enable-pnacl --no-first-run --user-data-dir=~/nacl_sdk/pepper_40/getting_started/part2/user-data-dir --allow-nacl-socket-api=localhost \ 
     --register-pepper-plugins="~/nacl_sdk/pepper_40/getting_started/part2/mac/Debug/part2.so;application/x-ppapi-debug~nacl_sdk/pepper_40/getting_started/part2/mac/Release/part2.so;application/x-ppapi-release" 
Serving ~/nacl_sdk/pepper_40/getting_started/part2 on http://localhost:5103/... 
Running: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --enable-nacl --enable-pnacl --no-first-run --user-data-dir=~/nacl_sdk/pepper_40/getting_started/part2/user-data-dir --allow-nacl-socket-api=localhost --register-pepper-plugins=~/nacl_sdk/pepper_40/getting_started/part2/mac/Debug/part2.so;application/x-ppapi-debug,~/nacl_sdk/pepper_40/getting_started/part2/mac/Release/part2.so;application/x-ppapi-release http://localhost:5103/index.html?tc=newlib&config=Release... 



Output : 

127.0.0.1 - - [10/Apr/2015 15:05:26] "GET /index.html?tc=newlib&config=Release HTTP/1.1" 200 - 
127.0.0.1 - - [10/Apr/2015 15:05:26] "GET /common.js HTTP/1.1" 200 - 
127.0.0.1 - - [10/Apr/2015 15:05:26] "GET /example.js HTTP/1.1" 200 - 
127.0.0.1 - - [10/Apr/2015 15:05:26] "GET /newlib/Release/part2.nmf HTTP/1.1" 200 - 
127.0.0.1 - - [10/Apr/2015 15:05:26] "GET /newlib/Release/part2_x86_64.nexe HTTP/1.1" 200 - 
127.0.0.1 - - [10/Apr/2015 15:05:26] code 404, message File not found 
127.0.0.1 - - [10/Apr/2015 15:05:26] "GET /favicon.ico HTTP/1.1" 404 - 
[43852,1925374720:15:05:26.885906] Native Client module will be loaded at base address 0x000052a200000000 
* Rebuilt URL to: www.google.com/ 
* timeout on name lookup is not supported 
* Hostname was NOT found in DNS cache 
* Curl_ipv4_resolve_r failed for www.google.com 
* Couldn't resolve host 'www.google.com' 
* Closing connection 0 
curl_easy_perform failed !! 
Reason : Couldn't resolve host name 
+0

Может ли кто-нибудь поделиться с помощью nacl curl (используя curl.a)? – kiran

ответ

0

мне удалось получить пример w orking (по крайней мере, для разрешения имен хостов) , изменив строку LIBS Makefile. Я удалил Glibc-Compat и переехал nacl_io до конца строки:

LIBS = ppapi_cpp ppapi pthread curl ssl crypto z nacl_io 

Причина это требовалось в том, что Glibc-Compat содержит много окурка/манекена/нерабочие функции, тогда как nacl_io содержит работу воплощения.

-Благодаря Сэм (из родных групп Google) для указания этой

+0

У меня подобная проблема. К сожалению, когда я удаляю 'glibc_compat' и перемещаю' nacl_io' в нижнюю часть, я получаю сообщение об ошибке: undefined to «alarm». Есть идеи? – mchiasson

+0

Я закончил это 'unsigned int alarm (unsigned int seconds) { return 0; } ' , и мне удалось связаться без glibc-compat. К сожалению, я все еще получаю 'Не удалось разрешить имя узла'. Я нахожусь на pepper_49 и скомпилирую libcurl через webports на ветке pepper_49. – mchiasson

0

Я пытаюсь построить локон с pepper_49, но есть еще некоторые проблемы при создании

Makefile:

LIBS = ppapi_cpp ppapi pthread curl ssl crypto z nacl_io 

строительство с TOOLCHAIN=pnacl make clean run

/Users/fu/nacl_sdk/pepper_49/tools/common.mk:500: Using chrome at: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome 
CXX pnacl/Release/hello_tutorial.o 
LINK pnacl/Release/curltest_unstripped.bc 
/Users/fu/nacl_sdk/pepper_49/toolchain/mac_pnacl/le32-nacl/usr/lib/libcurl.a: error: undefined reference to 'alarm' 
make: *** [pnacl/Release/curltest_unstripped.bc] Error 1 

Это после того, как я изменил Makefile на

LIBS = ppapi_cpp ppapi pthread curl ssl crypto z glibc-compat nacl_io 

и пример хорошо работает.

Смежные вопросы