OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <locale> | 6 #include <locale> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "net/base/ip_endpoint.h" | 31 #include "net/base/ip_endpoint.h" |
32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
33 #include "net/server/http_server.h" | 33 #include "net/server/http_server.h" |
34 #include "net/server/http_server_request_info.h" | 34 #include "net/server/http_server_request_info.h" |
35 #include "net/server/http_server_response_info.h" | 35 #include "net/server/http_server_response_info.h" |
36 #include "net/socket/tcp_server_socket.h" | 36 #include "net/socket/tcp_server_socket.h" |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char* kLocalHostAddress = "127.0.0.1"; | 40 const char* kLocalHostAddress = "127.0.0.1"; |
| 41 const int kBufferSize = 100 * 1024 * 1024; // 100 MB |
41 | 42 |
42 typedef base::Callback< | 43 typedef base::Callback< |
43 void(const net::HttpServerRequestInfo&, const HttpResponseSenderFunc&)> | 44 void(const net::HttpServerRequestInfo&, const HttpResponseSenderFunc&)> |
44 HttpRequestHandlerFunc; | 45 HttpRequestHandlerFunc; |
45 | 46 |
46 class HttpServer : public net::HttpServer::Delegate { | 47 class HttpServer : public net::HttpServer::Delegate { |
47 public: | 48 public: |
48 explicit HttpServer(const HttpRequestHandlerFunc& handle_request_func) | 49 explicit HttpServer(const HttpRequestHandlerFunc& handle_request_func) |
49 : handle_request_func_(handle_request_func), | 50 : handle_request_func_(handle_request_func), |
50 weak_factory_(this) {} | 51 weak_factory_(this) {} |
51 | 52 |
52 virtual ~HttpServer() {} | 53 virtual ~HttpServer() {} |
53 | 54 |
54 bool Start(int port, bool allow_remote) { | 55 bool Start(int port, bool allow_remote) { |
55 std::string binding_ip = kLocalHostAddress; | 56 std::string binding_ip = kLocalHostAddress; |
56 if (allow_remote) | 57 if (allow_remote) |
57 binding_ip = "0.0.0.0"; | 58 binding_ip = "0.0.0.0"; |
58 scoped_ptr<net::ServerSocket> server_socket( | 59 scoped_ptr<net::ServerSocket> server_socket( |
59 new net::TCPServerSocket(NULL, net::NetLog::Source())); | 60 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
60 server_socket->ListenWithAddressAndPort(binding_ip, port, 1); | 61 server_socket->ListenWithAddressAndPort(binding_ip, port, 1); |
61 server_.reset(new net::HttpServer(server_socket.Pass(), this)); | 62 server_.reset(new net::HttpServer(server_socket.Pass(), this)); |
62 net::IPEndPoint address; | 63 net::IPEndPoint address; |
63 return server_->GetLocalAddress(&address) == net::OK; | 64 return server_->GetLocalAddress(&address) == net::OK; |
64 } | 65 } |
65 | 66 |
66 // Overridden from net::HttpServer::Delegate: | 67 // Overridden from net::HttpServer::Delegate: |
| 68 virtual void OnConnect(int connection_id) OVERRIDE { |
| 69 server_->SetSendBufferSize(connection_id, kBufferSize); |
| 70 server_->SetReceiveBufferSize(connection_id, kBufferSize); |
| 71 } |
67 virtual void OnHttpRequest(int connection_id, | 72 virtual void OnHttpRequest(int connection_id, |
68 const net::HttpServerRequestInfo& info) OVERRIDE { | 73 const net::HttpServerRequestInfo& info) OVERRIDE { |
69 handle_request_func_.Run( | 74 handle_request_func_.Run( |
70 info, | 75 info, |
71 base::Bind(&HttpServer::OnResponse, | 76 base::Bind(&HttpServer::OnResponse, |
72 weak_factory_.GetWeakPtr(), | 77 weak_factory_.GetWeakPtr(), |
73 connection_id)); | 78 connection_id)); |
74 } | 79 } |
75 virtual void OnWebSocketRequest( | 80 virtual void OnWebSocketRequest( |
76 int connection_id, | 81 int connection_id, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 308 } |
304 | 309 |
305 if (!InitLogging()) { | 310 if (!InitLogging()) { |
306 printf("Unable to initialize logging. Exiting...\n"); | 311 printf("Unable to initialize logging. Exiting...\n"); |
307 return 1; | 312 return 1; |
308 } | 313 } |
309 RunServer(port, allow_remote, whitelisted_ips, | 314 RunServer(port, allow_remote, whitelisted_ips, |
310 url_base, adb_port, port_server.Pass()); | 315 url_base, adb_port, port_server.Pass()); |
311 return 0; | 316 return 0; |
312 } | 317 } |
OLD | NEW |