1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/at_exit.h" 6 #include "base/command_line.h" 7 #include "base/memory/singleton.h" 8 #include "base/message_loop/message_loop.h" 9 #include "base/metrics/stats_counters.h" 10 #include "net/base/completion_callback.h" 11 #include "net/base/io_buffer.h" 12 #include "net/base/net_errors.h" 13 #include "net/base/winsock_init.h" 14 #include "net/http/http_network_layer.h" 15 #include "net/http/http_request_info.h" 16 #include "net/http/http_transaction.h" 17 #include "net/proxy/proxy_service.h" 18 #include "net/tools/fetch/http_server.h" 19 usage(const char * program_name)20void usage(const char* program_name) { 21 printf("usage: %s\n", program_name); 22 exit(-1); 23 } 24 main(int argc,char ** argv)25int main(int argc, char**argv) { 26 base::AtExitManager exit; 27 base::StatsTable table("fetchserver", 50, 1000); 28 table.set_current(&table); 29 30 #if defined(OS_WIN) 31 net::EnsureWinsockInit(); 32 #endif // defined(OS_WIN) 33 34 CommandLine::Init(0, NULL); 35 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 36 37 // Do work here. 38 base::MessageLoop loop; 39 HttpServer server(std::string(), 40 80); // TODO(mbelshe): make port configurable 41 base::MessageLoop::current()->Run(); 42 43 if (parsed_command_line.HasSwitch("stats")) { 44 // Dump the stats table. 45 printf("<stats>\n"); 46 int counter_max = table.GetMaxCounters(); 47 for (int index=0; index < counter_max; index++) { 48 std::string name(table.GetRowName(index)); 49 if (name.length() > 0) { 50 int value = table.GetRowValue(index); 51 printf("%s:\t%d\n", name.c_str(), value); 52 } 53 } 54 printf("</stats>\n"); 55 } 56 57 } 58