MCPcopy Create free account
hub / github.com/LUX-Core/lux / WriteReply

Method WriteReply

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

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

Callers 9

RESTERRFunction · 0.80
rest_headersFunction · 0.80
rest_blockFunction · 0.80
rest_chaininfoFunction · 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