MCPcopy Create free account
hub / github.com/ElementsProject/elements / WriteReply

Method WriteReply

src/httpserver.cpp:568–596  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

566 * this cannot be done from worker threads.
567 */
568void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
569{
570 assert(!replySent && req);
571 if (ShutdownRequested()) {
572 WriteHeader("Connection", "close");
573 }
574 // Send event to main http thread to send reply message
575 struct evbuffer* evb = evhttp_request_get_output_buffer(req);
576 assert(evb);
577 evbuffer_add(evb, strReply.data(), strReply.size());
578 auto req_copy = req;
579 HTTPEvent* ev = new HTTPEvent(eventBase, true, [req_copy, nStatus]{
580 evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
581 // Re-enable reading from the socket. This is the second part of the libevent
582 // workaround above.
583 if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001) {
584 evhttp_connection* conn = evhttp_request_get_connection(req_copy);
585 if (conn) {
586 bufferevent* bev = evhttp_connection_get_bufferevent(conn);
587 if (bev) {
588 bufferevent_enable(bev, EV_READ | EV_WRITE);
589 }
590 }
591 }
592 });
593 ev->trigger(nullptr);
594 replySent = true;
595 req = nullptr; // transferred back to main thread
596}
597
598CService HTTPRequest::GetPeer() const
599{

Callers 14

RESTERRFunction · 0.80
rest_headersFunction · 0.80
rest_blockFunction · 0.80
rest_filter_headerFunction · 0.80
rest_block_filterFunction · 0.80
rest_chaininfoFunction · 0.80
rest_mempool_infoFunction · 0.80
rest_mempool_contentsFunction · 0.80
rest_txFunction · 0.80
rest_getutxosFunction · 0.80
rest_blockhash_by_heightFunction · 0.80
http_request_cbFunction · 0.80

Calls 4

ShutdownRequestedFunction · 0.85
triggerMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected