| 6 | #include "acl_cpp/lib_acl.hpp" |
| 7 | |
| 8 | class http_request : public acl::http_service_request |
| 9 | { |
| 10 | public: |
| 11 | http_request(const char* domain, unsigned short port, |
| 12 | acl::aio_handle* handle) |
| 13 | : acl::http_service_request(domain, port) |
| 14 | , handle_(handle) |
| 15 | { |
| 16 | read_length_ = 0; |
| 17 | } |
| 18 | |
| 19 | ~http_request(void) |
| 20 | { |
| 21 | printf("notify aio handle to stop!\r\n"); |
| 22 | // ֪ͨ�첽�¼�������ȫ�˳� |
| 23 | handle_->stop(); |
| 24 | } |
| 25 | protected: |
| 26 | ////////////////////////////////////////////////////////////////////////// |
| 27 | // ������ӿ� |
| 28 | |
| 29 | virtual const acl::string* get_body() |
| 30 | { |
| 31 | return (NULL); |
| 32 | } |
| 33 | |
| 34 | // �������� HTTP ��Ӧͷʱ�Ļص��ӿ� |
| 35 | virtual void on_hdr(const char* addr, const HTTP_HDR_RES* hdr) |
| 36 | { |
| 37 | printf(">>server addr: %s, http reply status: %d\n", |
| 38 | addr, hdr->reply_status); |
| 39 | http_hdr_print(&hdr->hdr, "http reply hdr"); |
| 40 | content_length_ = hdr->hdr.content_length; |
| 41 | if (content_length_ > 0) |
| 42 | { |
| 43 | if (out_.open_write("test.exe") == false) |
| 44 | printf("create file error(%s)\n", |
| 45 | acl_last_serror()); |
| 46 | } |
| 47 | time(&begin_); |
| 48 | } |
| 49 | |
| 50 | // ������ HTTP ��Ӧ��ʱ�Ļص����� |
| 51 | virtual void on_body(const char* data, size_t dlen) |
| 52 | { |
| 53 | if (data == NULL && dlen == 0) |
| 54 | { |
| 55 | #ifdef WIN32 |
| 56 | printf("\n>> http reply body over, total: %I64d, %I64d\n", |
| 57 | content_length_, read_length_); |
| 58 | #else |
| 59 | printf("\n>> http reply body over, total: %lld, %lld\n", |
| 60 | content_length_, read_length_); |
| 61 | #endif |
| 62 | // ��������Ϊ��������Ƕ�̬����ģ�������Ҫ�ڴ˴��ͷ� |
| 63 | time_t end = time(NULL); |
| 64 | printf(">>spent %d seconds\n", (int)(end - begin_)); |
| 65 |
no outgoing calls
no test coverage detected
searching dependent graphs…