OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/server/http_server.h" | 5 #include "net/server/http_server.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 DidClose(connection->socket_.get()); | 88 DidClose(connection->socket_.get()); |
89 } | 89 } |
90 | 90 |
91 int HttpServer::GetLocalAddress(IPEndPoint* address) { | 91 int HttpServer::GetLocalAddress(IPEndPoint* address) { |
92 if (!server_) | 92 if (!server_) |
93 return ERR_SOCKET_NOT_CONNECTED; | 93 return ERR_SOCKET_NOT_CONNECTED; |
94 return server_->GetLocalAddress(address); | 94 return server_->GetLocalAddress(address); |
95 } | 95 } |
96 | 96 |
97 void HttpServer::DidAccept(StreamListenSocket* server, | 97 void HttpServer::DidAccept(StreamListenSocket* server, |
98 StreamListenSocket* socket) { | 98 scoped_ptr<StreamListenSocket> socket) { |
99 HttpConnection* connection = new HttpConnection(this, socket); | 99 HttpConnection* connection = new HttpConnection(this, socket.Pass()); |
100 id_to_connection_[connection->id()] = connection; | 100 id_to_connection_[connection->id()] = connection; |
101 socket_to_connection_[socket] = connection; | 101 // TODO(szym): Fix socket access. Make HttpConnection the Delegate. |
| 102 socket_to_connection_[connection->socket_.get()] = connection; |
102 } | 103 } |
103 | 104 |
104 void HttpServer::DidRead(StreamListenSocket* socket, | 105 void HttpServer::DidRead(StreamListenSocket* socket, |
105 const char* data, | 106 const char* data, |
106 int len) { | 107 int len) { |
107 HttpConnection* connection = FindConnection(socket); | 108 HttpConnection* connection = FindConnection(socket); |
108 DCHECK(connection != NULL); | 109 DCHECK(connection != NULL); |
109 if (connection == NULL) | 110 if (connection == NULL) |
110 return; | 111 return; |
111 | 112 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 HttpConnection* connection = FindConnection(socket); | 174 HttpConnection* connection = FindConnection(socket); |
174 DCHECK(connection != NULL); | 175 DCHECK(connection != NULL); |
175 id_to_connection_.erase(connection->id()); | 176 id_to_connection_.erase(connection->id()); |
176 socket_to_connection_.erase(connection->socket_.get()); | 177 socket_to_connection_.erase(connection->socket_.get()); |
177 delete connection; | 178 delete connection; |
178 } | 179 } |
179 | 180 |
180 HttpServer::~HttpServer() { | 181 HttpServer::~HttpServer() { |
181 STLDeleteContainerPairSecondPointers( | 182 STLDeleteContainerPairSecondPointers( |
182 id_to_connection_.begin(), id_to_connection_.end()); | 183 id_to_connection_.begin(), id_to_connection_.end()); |
183 server_ = NULL; | |
184 } | 184 } |
185 | 185 |
186 // | 186 // |
187 // HTTP Request Parser | 187 // HTTP Request Parser |
188 // This HTTP request parser uses a simple state machine to quickly parse | 188 // This HTTP request parser uses a simple state machine to quickly parse |
189 // through the headers. The parser is not 100% complete, as it is designed | 189 // through the headers. The parser is not 100% complete, as it is designed |
190 // for use in this simple test driver. | 190 // for use in this simple test driver. |
191 // | 191 // |
192 // Known issues: | 192 // Known issues: |
193 // - does not handle whitespace on first HTTP line correctly. Expects | 193 // - does not handle whitespace on first HTTP line correctly. Expects |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 321 } |
322 | 322 |
323 HttpConnection* HttpServer::FindConnection(StreamListenSocket* socket) { | 323 HttpConnection* HttpServer::FindConnection(StreamListenSocket* socket) { |
324 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); | 324 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); |
325 if (it == socket_to_connection_.end()) | 325 if (it == socket_to_connection_.end()) |
326 return NULL; | 326 return NULL; |
327 return it->second; | 327 return it->second; |
328 } | 328 } |
329 | 329 |
330 } // namespace net | 330 } // namespace net |
OLD | NEW |