src/httpserver.cpp
void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
{
    assert(!replySent && req);
    if (ShutdownRequested()) {
        WriteHeader("Connection", "close");
    }
    // Send event to main http thread to send reply message
    struct evbuffer* evb = evhttp_request_get_output_buffer(req);
    assert(evb);
    evbuffer_add(evb, strReply.data(), strReply.size());
    auto req_copy = req;
    HTTPEvent* ev = new HTTPEvent(eventBase, true, nullptr, [req_copy, nStatus]{
        evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
        // Re-enable reading from the socket. This is the second part of the libevent
        // workaround above.
        if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001) {
            evhttp_connection* conn = evhttp_request_get_connection(req_copy);
            if (conn) {
                bufferevent* bev = evhttp_connection_get_bufferevent(conn);
                if (bev) {
                    bufferevent_enable(bev, EV_READ | EV_WRITE);
                }
            }
        }
    });
    ev->trigger(nullptr);
    replySent = true;
    req = nullptr; // transferred back to main thread
}
/** 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.
 */
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.
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 .
void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
{
    assert(!replySent && req);
    if (ShutdownRequested()) {
        WriteHeader("Connection", "close");
    }
    struct evbuffer* evb = evhttp_request_get_output_buffer(req);
    assert(evb);
    evbuffer_add(evb, strReply.data(), strReply.size());
    auto req_copy = req;
    HTTPEvent* ev = new HTTPEvent(eventBase, true, nullptr, [req_copy, nStatus]{
        evhttp_send_reply(req_copy, nStatus, nullptr, nullptr);
        if (event_get_version_number() >= 0x02010600 && event_get_version_number() < 0x02020001) {
            evhttp_connection* conn = evhttp_request_get_connection(req_copy);
            if (conn) {
                bufferevent* bev = evhttp_connection_get_bufferevent(conn);
                if (bev) {
                    bufferevent_enable(bev, EV_READ | EV_WRITE);
                }
            }
        }
    });
    ev->trigger(nullptr);
    replySent = true;
    req = nullptr; 
}
void HTTPRequest :: WriteReply ( int nStatus , const std :: string & strReply ) { assert ( ! replySent && req ) ; if ( ShutdownRequested ( ) ) { WriteHeader ( " " , " " ) ; } struct evbuffer * evb = evhttp_request_get_output_buffer ( req ) ; assert ( evb ) ; evbuffer_add ( evb , strReply . data ( ) , strReply . size ( ) ) ; auto req_copy = req ; HTTPEvent * ev = new HTTPEvent ( eventBase , true , nullptr , [ req_copy , nStatus ] { evhttp_send_reply ( req_copy , nStatus , nullptr , nullptr ) ; if ( event_get_version_number ( ) >= 0x02010600 && event_get_version_number ( ) < 0x02020001 ) { evhttp_connection * conn = evhttp_request_get_connection ( req_copy ) ; if ( conn ) { bufferevent * bev = evhttp_connection_get_bufferevent ( conn ) ; if ( bev ) { bufferevent_enable ( bev , EV_READ | EV_WRITE ) ; } } } } ) ; ev -> trigger ( nullptr ) ; replySent = true ; req = nullptr ; }
Closure sent to main thread to request a reply to be sent to
 a HTTP request.
Closure sent to main thread to request a reply to be sent to a HTTP request .
// Send event to main http thread to send reply message // Re-enable reading from the socket. This is the second part of the libevent // workaround above. // transferred back to main thread