MCPcopy Create free account
hub / github.com/BitcoinUnlimited/BitcoinUnlimited / WriteReply

Method WriteReply

src/httpserver.cpp:644–674  ·  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

642 * this cannot be done from worker threads.
643 */
644void HTTPRequest::WriteReply(int nStatus, const std::string &strReply)
645{
646 assert(!replySent && req);
647 // Send event to main http thread to send reply message
648 struct evbuffer *evb = evhttp_request_get_output_buffer(req);
649 assert(evb);
650 evbuffer_add(evb, strReply.data(), strReply.size());
651 auto req_copy = req;
652 HTTPEvent *ev = new HTTPEvent(eventBase, true,
653 [req_copy, nStatus]
654 {
655 evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
656 // Re-enable reading from the socket. This is the second part of the libevent
657 // workaround above.
658 if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001)
659 {
660 evhttp_connection *conn = evhttp_request_get_connection(req_copy);
661 if (conn)
662 {
663 bufferevent *bev = evhttp_connection_get_bufferevent(conn);
664 if (bev)
665 {
666 bufferevent_enable(bev, EV_READ | EV_WRITE);
667 }
668 }
669 }
670 });
671 ev->trigger(nullptr);
672 replySent = true;
673 req = nullptr; // transferred back to main thread
674}
675
676CService HTTPRequest::GetPeer()
677{

Callers 11

RESTERRFunction · 0.80
rest_headersFunction · 0.80
rest_blockFunction · 0.80
rest_chaininfoFunction · 0.80
rest_mempool_infoFunction · 0.80
rest_mempool_contentsFunction · 0.80
rest_txFunction · 0.80
rest_getutxosFunction · 0.80
http_request_cbFunction · 0.80
JSONErrorReplyFunction · 0.80
HTTPReq_JSONRPCFunction · 0.80

Calls 3

triggerMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected