user31217: Source code (src/httpserver.cpp):
static void ThreadHTTP(struct event_base* base, struct evhttp* http)
{
    RenameThread("bitcoin-http");
    LogPrint("http", "Entering http event loop\n");
    event_base_dispatch(base);
    // Event loop will be interrupted by InterruptHTTPServer()
    LogPrint("http", "Exited http event loop\n");
}

Can anyone help me understand this portion of logic? In particular 

What is the HTTP magic happening here event_base_dispatch(base)?
Why are we renaming threads?


user2306: event_base_dispatch is part of libevent, a library that takes events from network sockets, and uses them to call callbacks in your program. To find out what it's calling, you should look at the struct event_base* base variable.
bool InitHTTPServer()
{
    // [...]
    base = event_base_new(); // XXX RAII
    // [...]
    http = evhttp_new(base); // XXX RAII
    // [...]
    evhttp_set_gencb(http, http_request_cb, NULL);

There are three important calls here. event_base_new creates the struct that tells event_base_dispatch how to handle incoming connections. evhttp_new tells libevent to interpret incoming data as the HTTP protocol, instead of passing along raw bytes. evhttp_set_gencb tells libevent which function to call when new requests come in. This is where that ends:
/** HTTP request callback */
static void http_request_cb(struct evhttp_request* req, void* arg)


Why are we renaming threads?

Debuggging and performance logging.

31217: <p>Source code (<code>src/httpserver.cpp</code>):</p>

<pre><code>static void ThreadHTTP(struct event_base* base, struct evhttp* http)
{
    RenameThread("bitcoin-http");
    LogPrint("http", "Entering http event loop\n");
    event_base_dispatch(base);
    // Event loop will be interrupted by InterruptHTTPServer()
    LogPrint("http", "Exited http event loop\n");
}
</code></pre>

<p>Can anyone help me understand this portion of logic? In particular </p>

<ul>
<li>What is the HTTP magic happening here <code>event_base_dispatch(base)</code>?</li>
<li>Why are we renaming threads?</li>
</ul>
 2306: <p><code>event_base_dispatch</code> is part of libevent, a library that takes events from network sockets, and uses them to call callbacks in your program. To find out what it's calling, you should look at the <code>struct event_base* base</code> variable.</p>

<pre><code>bool InitHTTPServer()
{
    // [...]
    base = event_base_new(); // XXX RAII
    // [...]
    http = evhttp_new(base); // XXX RAII
    // [...]
    evhttp_set_gencb(http, http_request_cb, NULL);
</code></pre>

<p>There are three important calls here. <code>event_base_new</code> creates the struct that tells <code>event_base_dispatch</code> how to handle incoming connections. <code>evhttp_new</code> tells libevent to interpret incoming data as the HTTP protocol, instead of passing along raw bytes. <code>evhttp_set_gencb</code> tells libevent which function to call when new requests come in. This is where that ends:</p>

<pre><code>/** HTTP request callback */
static void http_request_cb(struct evhttp_request* req, void* arg)
</code></pre>

<blockquote>
  <p>Why are we renaming threads?</p>
</blockquote>

<p>Debuggging and performance logging.</p>
