| 62 | } |
| 63 | |
| 64 | bool http_request::rpc_request(const MessageLite& in, MessageLite* out) |
| 65 | { |
| 66 | if (request_ == NULL) |
| 67 | { |
| 68 | if (addr_ == NULL) |
| 69 | return false; |
| 70 | request_inner_ = new acl::http_request(addr_, |
| 71 | conn_timeout_, rw_timeout_); |
| 72 | request_ = request_inner_; |
| 73 | } |
| 74 | |
| 75 | std::string buf; |
| 76 | |
| 77 | #ifdef DEBUG |
| 78 | struct timeval begin, end; |
| 79 | gettimeofday(&begin, NULL); |
| 80 | #endif |
| 81 | |
| 82 | in.SerializeToString(&buf); |
| 83 | |
| 84 | #ifdef DEBUG |
| 85 | gettimeofday(&end, NULL); |
| 86 | build_spent_ = stamp_sub(&end, &begin); |
| 87 | |
| 88 | gettimeofday(&begin, NULL); |
| 89 | #endif |
| 90 | acl::http_header& header = request_->request_header(); |
| 91 | header.set_content_length(buf.length()); |
| 92 | header.set_keep_alive(true); |
| 93 | |
| 94 | if (request_->request(buf.c_str(), buf.length()) == false) |
| 95 | return false; |
| 96 | |
| 97 | #ifdef DEBUG |
| 98 | gettimeofday(&end, NULL); |
| 99 | request_spent_ = stamp_sub(&end, &begin); |
| 100 | #endif |
| 101 | |
| 102 | if (out == NULL) |
| 103 | return true; |
| 104 | |
| 105 | buf.clear(); |
| 106 | acl::string tmp; |
| 107 | int ret; |
| 108 | |
| 109 | #ifdef DEBUG |
| 110 | gettimeofday(&begin, NULL); |
| 111 | #endif |
| 112 | while (true) |
| 113 | { |
| 114 | ret = request_->read_body(tmp, true); |
| 115 | if (ret < 0) |
| 116 | return false; |
| 117 | else if (ret == 0) |
| 118 | break; |
| 119 | buf.append(tmp.c_str(), (size_t) ret); |
| 120 | } |
| 121 |
no test coverage detected