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

Function http_get

lib_acl_cpp/samples/http_request_manager/main.cpp:84–138  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

82
83// HTTP ������̣�����������������ӷ�������ȡ��Ӧ����
84static bool http_get(http_request* conn, const char* addr, int n)
85{
86 if (__debug) {
87 printf(">>>check addr: %s, n: %d\r\n", addr, n);
88 }
89
90 // ���� HTTP ����ͷ����
91 http_header& header = conn->request_header();
92 header.set_url("/")
93 .set_host(addr)
94 .set_keep_alive(true)
95 .set_method(HTTP_METHOD_GET)
96 .accept_gzip(__unzip);
97
98 if (__debug) {
99 printf("%lu--%d: begin send request\r\n",
100 (unsigned long) acl_pthread_self(), n);
101 }
102 // ���� HTTP ��������ͬʱ���� HTTP ��Ӧͷ
103 if (conn->request(NULL, 0) == false) {
104 printf("%lu--%d: send GET request error\r\n",
105 (unsigned long) acl_pthread_self(), n);
106 return false;
107 }
108
109 char buf[8192];
110 int ret, length = 0;
111
112 // ���� HTTP ��Ӧ������
113 while (true) {
114 ret = conn->read_body(buf, sizeof(buf) - 1);
115 if (ret == 0) {
116 break;
117 } else if (ret < 0) {
118 printf("%lu--%d: error, length: %d\r\n",
119 (unsigned long) acl_pthread_self(),
120 n, length);
121 return false;
122 }
123 //buf[ret] = 0;
124 //printf("%s", buf);fflush(stdout);
125
126 length += ret;
127 if (__debug) {
128 printf("%lu--%d: read length: %d, %d\r\n",
129 (unsigned long) acl_pthread_self(),
130 n, length, ret);
131 }
132 }
133 if (__debug) {
134 printf("%lu--%d: read body over, length: %d\r\n",
135 (unsigned long) acl_pthread_self(), n, length);
136 }
137 return true;
138}
139
140static void check_all_connections(void)
141{

Callers 1

thread_mainFunction · 0.70

Calls 6

acl_pthread_selfFunction · 0.85
request_headerMethod · 0.80
accept_gzipMethod · 0.80
set_keep_aliveMethod · 0.80
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…