MCPcopy Create free account
hub / github.com/Raptor3um/raptoreum / WriteReply

Method WriteReply

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

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

Callers 12

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 4

triggerMethod · 0.80
ShutdownRequestedFunction · 0.70
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected