HTTP ������̣�����������������ӷ�������ȡ��Ӧ����
| 31 | |
| 32 | // HTTP ������̣�����������������ӷ�������ȡ��Ӧ���� |
| 33 | static 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 | // �̴߳������� |
| 83 | static void thread_main(void*) |
no test coverage detected
searching dependent graphs…