Closure sent to main thread to request a reply to be sent to a HTTP request. * Replies must be sent in the main loop in the main http thread, this cannot be * done from worker threads. */
| 524 | * done from worker threads. |
| 525 | */ |
| 526 | void HTTPRequest::WriteReply(int nStatus, const std::string &strReply) { |
| 527 | assert(!replySent && req); |
| 528 | // Send event to main http thread to send reply message |
| 529 | struct evbuffer *evb = evhttp_request_get_output_buffer(req); |
| 530 | assert(evb); |
| 531 | evbuffer_add(evb, strReply.data(), strReply.size()); |
| 532 | HTTPEvent *ev = |
| 533 | new HTTPEvent(eventBase, true, std::bind(evhttp_send_reply, req, |
| 534 | nStatus, (const char *)nullptr, |
| 535 | (struct evbuffer *)nullptr)); |
| 536 | ev->trigger(0); |
| 537 | replySent = true; |
| 538 | // transferred back to main thread. |
| 539 | req = 0; |
| 540 | } |
| 541 | |
| 542 | void HTTPRequest::StartWritingChunks(int nStatus) { |
| 543 | HTTPEvent *ev = new HTTPEvent(eventBase, true, std::bind(evhttp_send_reply_start, req, nStatus, (const char *)nullptr)); |
no test coverage detected