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

Method WriteReply

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

584 * this cannot be done from worker threads.
585 */
586void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
587{
588 assert(!replySent && req);
589 // Send event to main http thread to send reply message
590 struct evbuffer* evb = evhttp_request_get_output_buffer(req);
591 assert(evb);
592 evbuffer_add(evb, strReply.data(), strReply.size());
593 auto req_copy = req;
594 HTTPEvent* ev = new HTTPEvent(eventBase, true, [req_copy, nStatus]{
595 evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
596 // Re-enable reading from the socket. This is the second part of the libevent
597 // workaround above.
598 if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001) {
599 evhttp_connection* conn = evhttp_request_get_connection(req_copy);
600 if (conn) {
601 bufferevent* bev = evhttp_connection_get_bufferevent(conn);
602 if (bev) {
603 bufferevent_enable(bev, EV_READ | EV_WRITE);
604 }
605 }
606 }
607 });
608 ev->trigger(nullptr);
609 replySent = true;
610 req = nullptr; // transferred back to main thread
611}
612
613CService HTTPRequest::GetPeer()
614{

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