MCPcopy Create free account
hub / github.com/acl-dev/acl / run

Method run

android/samples/fiber/http/src/main/cpp/http_get.cpp:43–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void http_get::run(void) {
44 log_info("http_get(%d): host=%s, port=%d, url=%s", __LINE__,
45 task_->get_server_host().c_str(), task_->get_server_port(),
46 task_->get_server_url().c_str());
47 task_->debug();
48
49 const char* host = task_->get_server_host().c_str();
50 std::vector<acl::string> ips;
51
52 int err = 0;
53 go_wait_thread[&] {
54 log_info("begin resolve host=%s", host);
55 // resolve domain in a thread to avoid blocking the fiber thread scheule.
56#if 1
57 struct hostent* ent = gethostbyname(host);
58 if (ent == NULL) {
59 err = h_errno;
60 log_error("can't get addr for host=%s, %s", host, hstrerror(h_errno));
61 return;
62 }
63 char ip[64];
64 for (char** pptr = ent->h_addr_list; *pptr != NULL; pptr++) {
65 if (inet_ntop(ent->h_addrtype, *pptr, ip, sizeof(ip))) {
66 ips.push_back(ip);
67 log_info("http_get::run: one ip: %s", ip);
68 }
69 }
70#else
71 ACL_DNS_DB* db = acl_gethostbyname(host, &errnum);
72 if (db == NULL) {
73 logger_error("gethostbyname error=%s, domain=%s, herr=%d",
74 acl_netdb_strerror(errnum), host, errnum);
75 return;
76 }
77 ACL_ITER iter;
78 acl_foreach(iter, db) {
79 const ACL_HOSTNAME* hn = (const ACL_HOSTNAME*) iter.data;
80 if (hn->saddr.sa.sa_family == AF_INET) {
81 ips.push_back(hn->ip);
82 } else if (hn->saddr.sa.sa_family == AF_INET6) {
83 ips.push_back(hn->ip);
84 } else {
85 log_info("domain=%s, ipv=%s, type=%d", host, hn->ip,
86 hn->saddr.sa.sa_family);
87 }
88 }
89 acl_netdb_free(db);
90#endif
91 };
92
93 if (ips.empty()) {
94 log_error("resolve domain(%s) failed", host);

Callers

nothing calls this directly

Calls 11

inet_ntopFunction · 0.85
acl_gethostbynameFunction · 0.85
acl_netdb_strerrorFunction · 0.85
acl_netdb_freeFunction · 0.85
get_server_portMethod · 0.80
log_infoFunction · 0.70
log_errorFunction · 0.70
gethostbynameFunction · 0.50
c_strMethod · 0.45
debugMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected