HTTP ������̣�����������������ӷ�������ȡ��Ӧ����
| 82 | |
| 83 | // HTTP ������̣�����������������ӷ�������ȡ��Ӧ���� |
| 84 | static 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 | |
| 140 | static void check_all_connections(void) |
| 141 | { |
no test coverage detected
searching dependent graphs…