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

Method run

android/samples/fiber/HttpFiber/src/main/cpp/http_get.cpp:44–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected