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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 binding_ip = "0.0.0.0"; | 58 binding_ip = "0.0.0.0"; |
59 scoped_ptr<net::ServerSocket> server_socket( | 59 scoped_ptr<net::ServerSocket> server_socket( |
60 new net::TCPServerSocket(NULL, net::NetLog::Source())); | 60 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
61 server_socket->ListenWithAddressAndPort(binding_ip, port, 1); | 61 server_socket->ListenWithAddressAndPort(binding_ip, port, 1); |
62 server_.reset(new net::HttpServer(server_socket.Pass(), this)); | 62 server_.reset(new net::HttpServer(server_socket.Pass(), this)); |
63 net::IPEndPoint address; | 63 net::IPEndPoint address; |
64 return server_->GetLocalAddress(&address) == net::OK; | 64 return server_->GetLocalAddress(&address) == net::OK; |
65 } | 65 } |
66 | 66 |
67 // Overridden from net::HttpServer::Delegate: | 67 // Overridden from net::HttpServer::Delegate: |
68 virtual void OnConnect(int connection_id) OVERRIDE { | 68 virtual void OnConnect(int connection_id) override { |
69 server_->SetSendBufferSize(connection_id, kBufferSize); | 69 server_->SetSendBufferSize(connection_id, kBufferSize); |
70 server_->SetReceiveBufferSize(connection_id, kBufferSize); | 70 server_->SetReceiveBufferSize(connection_id, kBufferSize); |
71 } | 71 } |
72 virtual void OnHttpRequest(int connection_id, | 72 virtual void OnHttpRequest(int connection_id, |
73 const net::HttpServerRequestInfo& info) OVERRIDE { | 73 const net::HttpServerRequestInfo& info) override { |
74 handle_request_func_.Run( | 74 handle_request_func_.Run( |
75 info, | 75 info, |
76 base::Bind(&HttpServer::OnResponse, | 76 base::Bind(&HttpServer::OnResponse, |
77 weak_factory_.GetWeakPtr(), | 77 weak_factory_.GetWeakPtr(), |
78 connection_id)); | 78 connection_id)); |
79 } | 79 } |
80 virtual void OnWebSocketRequest( | 80 virtual void OnWebSocketRequest( |
81 int connection_id, | 81 int connection_id, |
82 const net::HttpServerRequestInfo& info) OVERRIDE {} | 82 const net::HttpServerRequestInfo& info) override {} |
83 virtual void OnWebSocketMessage(int connection_id, | 83 virtual void OnWebSocketMessage(int connection_id, |
84 const std::string& data) OVERRIDE {} | 84 const std::string& data) override {} |
85 virtual void OnClose(int connection_id) OVERRIDE {} | 85 virtual void OnClose(int connection_id) override {} |
86 | 86 |
87 private: | 87 private: |
88 void OnResponse(int connection_id, | 88 void OnResponse(int connection_id, |
89 scoped_ptr<net::HttpServerResponseInfo> response) { | 89 scoped_ptr<net::HttpServerResponseInfo> response) { |
90 // Don't support keep-alive, since there's no way to detect if the | 90 // Don't support keep-alive, since there's no way to detect if the |
91 // client is HTTP/1.0. In such cases, the client may hang waiting for | 91 // client is HTTP/1.0. In such cases, the client may hang waiting for |
92 // the connection to close (e.g., python 2.7 urllib). | 92 // the connection to close (e.g., python 2.7 urllib). |
93 response->AddHeader("Connection", "close"); | 93 response->AddHeader("Connection", "close"); |
94 server_->SendResponse(connection_id, *response); | 94 server_->SendResponse(connection_id, *response); |
95 // Don't need to call server_->Close(), since SendResponse() will handle | 95 // Don't need to call server_->Close(), since SendResponse() will handle |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 | 309 |
310 if (!InitLogging()) { | 310 if (!InitLogging()) { |
311 printf("Unable to initialize logging. Exiting...\n"); | 311 printf("Unable to initialize logging. Exiting...\n"); |
312 return 1; | 312 return 1; |
313 } | 313 } |
314 RunServer(port, allow_remote, whitelisted_ips, | 314 RunServer(port, allow_remote, whitelisted_ips, |
315 url_base, adb_port, port_server.Pass()); | 315 url_base, adb_port, port_server.Pass()); |
316 return 0; | 316 return 0; |
317 } | 317 } |
OLD | NEW |