| 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_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Initiating close from server-side does not lead to the DidClose call. | 85 // Initiating close from server-side does not lead to the DidClose call. |
| 86 // Do it manually here. | 86 // Do it manually here. |
| 87 DidClose(connection->socket_.get()); | 87 DidClose(connection->socket_.get()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 int HttpServer::GetLocalAddress(IPEndPoint* address) { | 90 int HttpServer::GetLocalAddress(IPEndPoint* address) { |
| 91 return server_->GetLocalAddress(address); | 91 return server_->GetLocalAddress(address); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void HttpServer::DidAccept(StreamListenSocket* server, | 94 void HttpServer::DidAccept(StreamListenSocket* server, |
| 95 StreamListenSocket* socket) { | 95 scoped_ptr<StreamListenSocket> socket) { |
| 96 HttpConnection* connection = new HttpConnection(this, socket); | 96 HttpConnection* connection = new HttpConnection(this, socket.Pass()); |
| 97 id_to_connection_[connection->id()] = connection; | 97 id_to_connection_[connection->id()] = connection; |
| 98 socket_to_connection_[socket] = connection; | 98 // TODO(szym): Fix socket access. Make HttpConnection the Delegate. |
| 99 socket_to_connection_[connection->socket_.get()] = connection; |
| 99 } | 100 } |
| 100 | 101 |
| 101 void HttpServer::DidRead(StreamListenSocket* socket, | 102 void HttpServer::DidRead(StreamListenSocket* socket, |
| 102 const char* data, | 103 const char* data, |
| 103 int len) { | 104 int len) { |
| 104 HttpConnection* connection = FindConnection(socket); | 105 HttpConnection* connection = FindConnection(socket); |
| 105 DCHECK(connection != NULL); | 106 DCHECK(connection != NULL); |
| 106 if (connection == NULL) | 107 if (connection == NULL) |
| 107 return; | 108 return; |
| 108 | 109 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 HttpConnection* connection = FindConnection(socket); | 151 HttpConnection* connection = FindConnection(socket); |
| 151 DCHECK(connection != NULL); | 152 DCHECK(connection != NULL); |
| 152 id_to_connection_.erase(connection->id()); | 153 id_to_connection_.erase(connection->id()); |
| 153 socket_to_connection_.erase(connection->socket_.get()); | 154 socket_to_connection_.erase(connection->socket_.get()); |
| 154 delete connection; | 155 delete connection; |
| 155 } | 156 } |
| 156 | 157 |
| 157 HttpServer::~HttpServer() { | 158 HttpServer::~HttpServer() { |
| 158 STLDeleteContainerPairSecondPointers( | 159 STLDeleteContainerPairSecondPointers( |
| 159 id_to_connection_.begin(), id_to_connection_.end()); | 160 id_to_connection_.begin(), id_to_connection_.end()); |
| 160 server_ = NULL; | |
| 161 } | 161 } |
| 162 | 162 |
| 163 // | 163 // |
| 164 // HTTP Request Parser | 164 // HTTP Request Parser |
| 165 // This HTTP request parser uses a simple state machine to quickly parse | 165 // This HTTP request parser uses a simple state machine to quickly parse |
| 166 // through the headers. The parser is not 100% complete, as it is designed | 166 // through the headers. The parser is not 100% complete, as it is designed |
| 167 // for use in this simple test driver. | 167 // for use in this simple test driver. |
| 168 // | 168 // |
| 169 // Known issues: | 169 // Known issues: |
| 170 // - does not handle whitespace on first HTTP line correctly. Expects | 170 // - does not handle whitespace on first HTTP line correctly. Expects |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 299 } |
| 300 | 300 |
| 301 HttpConnection* HttpServer::FindConnection(StreamListenSocket* socket) { | 301 HttpConnection* HttpServer::FindConnection(StreamListenSocket* socket) { |
| 302 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); | 302 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); |
| 303 if (it == socket_to_connection_.end()) | 303 if (it == socket_to_connection_.end()) |
| 304 return NULL; | 304 return NULL; |
| 305 return it->second; | 305 return it->second; |
| 306 } | 306 } |
| 307 | 307 |
| 308 } // namespace net | 308 } // namespace net |
| OLD | NEW |