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

Method WriteReply

src/rpc/core/httpserver.cpp:578–605  ·  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

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

Callers 3

http_request_cbFunction · 0.80
ErrorReplyFunction · 0.80
JsonRPCHandlerFunction · 0.80

Calls 4

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

Tested by

no test coverage detected