Mongoose Embedded Webserver
<p>This code is taken from the example program in Mongoose embedded web server. </p>

<p>The event MG_NEW_REQUEST is called twice. Is this the expected behavior? Why would it process the same request twice? How would you prevent this from doing so?</p>

<pre><code>int i =0;
static void *callback(enum mg_event event,
                      struct mg_connection *conn,
                      const struct mg_request_info *request_info)
{
  if (event == MG_NEW_REQUEST)
  {

      i++;
      printf("%d \n", i);

    // Echo requested URI back to the client
    mg_printf(conn, "HTTP/1.1 200 OK\r\n"
              "Content-Type: text/html\r\n\r\n"
              "%s", request_info-&gt;uri);

    mg_printf(conn, "Hello World!!"
                  "%s", "");

    //request_info-&gt;query_string
    return const_cast&lt;char *&gt;("done");  // Mark as processed
  }
  else
  {
    return NULL;
  }
}

int main(void) {
  struct mg_context *ctx;
  const char *options[] = {"listening_ports", "8080", NULL};

  printf("Test web server, open browser to http://localhost:8080 ");
  ctx = mg_start(&amp;callback, NULL, options);
  getchar();  // Wait until user hits "enter"
  mg_stop(ctx);

  return 0;
}
</code></pre>
