MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / WriteReply

Method WriteReply

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

699 * done from worker threads.
700 */
701void HTTPRequest::WriteReply(int nStatus, const std::string &strReply) {
702 assert(!replySent && req);
703 if (ShutdownRequested()) {
704 WriteHeader("Connection", "close");
705 }
706 // Send event to main http thread to send reply message
707 struct evbuffer *evb = evhttp_request_get_output_buffer(req);
708 assert(evb);
709 evbuffer_add(evb, strReply.data(), strReply.size());
710 auto req_copy = req;
711 HTTPEvent *ev = new HTTPEvent(eventBase, true, [req_copy, nStatus] {
712 evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
713 // Re-enable reading from the socket. This is the second part of the
714 // libevent workaround above.
715 if (event_get_version_number() >= 0x02010600 &&
716 event_get_version_number() < 0x02020001) {
717 evhttp_connection *conn = evhttp_request_get_connection(req_copy);
718 if (conn) {
719 bufferevent *bev = evhttp_connection_get_bufferevent(conn);
720 if (bev) {
721 bufferevent_enable(bev, EV_READ | EV_WRITE);
722 }
723 }
724 }
725 });
726 ev->trigger(nullptr);
727 replySent = true;
728 // transferred back to main thread.
729 req = nullptr;
730}
731
732CService HTTPRequest::GetPeer() const {
733 evhttp_connection *con = evhttp_request_get_connection(req);

Callers 13

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
rest_blockhash_by_heightFunction · 0.80
http_request_cbFunction · 0.80
JSONErrorReplyFunction · 0.80
checkCORSFunction · 0.80

Calls 4

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

Tested by

no test coverage detected