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

Function http_get

lib_acl_cpp/samples/http_request_pool/main.cpp:33–80  ·  view source on GitHub ↗

HTTP ������̣�����������������ӷ�������ȡ��Ӧ����

Source from the content-addressed store, hash-verified

31
32// HTTP ������̣�����������������ӷ�������ȡ��Ӧ����
33static bool http_get(http_request* conn, int n)
34{
35 // ���� HTTP ����ͷ����
36 http_header& header = conn->request_header();
37 header.set_url("/")
38 .set_keep_alive(true)
39 .set_method(HTTP_METHOD_GET)
40 .accept_gzip(__unzip);
41 if (!__host.empty()) {
42 header.set_host(__host);
43 }
44
45 if (__debug) {
46 printf("%lu--%d: begin send request\r\n",
47 (unsigned long) acl_pthread_self(), n);
48 }
49 // ���� HTTP ��������ͬʱ���� HTTP ��Ӧͷ
50 if (conn->request(NULL, 0) == false) {
51 printf("%lu--%d: send GET request error\r\n",
52 (unsigned long) acl_pthread_self(), n);
53 return false;
54 }
55
56 char buf[8192];
57 int ret, length = 0;
58
59 // ���� HTTP ��Ӧ������
60 while (true) {
61 ret = conn->read_body(buf, sizeof(buf));
62 if (ret == 0) {
63 break;
64 } else if (ret < 0) {
65 printf("%lu--%d: error, length: %d\r\n",
66 (unsigned long) acl_pthread_self(), n, length);
67 return false;
68 }
69 length += ret;
70 if (__debug) {
71 printf("%lu--%d: read length: %d, %d\r\n",
72 (unsigned long) acl_pthread_self(), n, length, ret);
73 }
74 }
75 if (__debug) {
76 printf("%lu--%d: read body over, length: %d\r\n",
77 (unsigned long) acl_pthread_self(), n, length);
78 }
79 return true;
80}
81
82// �̴߳�������
83static void thread_main(void*)

Callers 1

thread_mainFunction · 0.70

Calls 7

acl_pthread_selfFunction · 0.85
request_headerMethod · 0.80
accept_gzipMethod · 0.80
set_keep_aliveMethod · 0.80
emptyMethod · 0.45
requestMethod · 0.45
read_bodyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…