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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 { | 86 { |
87 HttpConnection* connection = FindConnection(connection_id); | 87 HttpConnection* connection = FindConnection(connection_id); |
88 if (connection == NULL) | 88 if (connection == NULL) |
89 return; | 89 return; |
90 | 90 |
91 // Initiating close from server-side does not lead to the DidClose call. | 91 // Initiating close from server-side does not lead to the DidClose call. |
92 // Do it manually here. | 92 // Do it manually here. |
93 DidClose(connection->socket_); | 93 DidClose(connection->socket_); |
94 } | 94 } |
95 | 95 |
96 void HttpServer::DidAccept(ListenSocket* server, | 96 void HttpServer::DidAccept(StreamListenSocket* server, |
97 ListenSocket* socket) { | 97 StreamListenSocket* socket) { |
98 HttpConnection* connection = new HttpConnection(this, socket); | 98 HttpConnection* connection = new HttpConnection(this, socket); |
99 id_to_connection_[connection->id()] = connection; | 99 id_to_connection_[connection->id()] = connection; |
100 socket_to_connection_[socket] = connection; | 100 socket_to_connection_[socket] = connection; |
101 } | 101 } |
102 | 102 |
103 void HttpServer::DidRead(ListenSocket* socket, | 103 void HttpServer::DidRead(StreamListenSocket* socket, |
104 const char* data, | 104 const char* data, |
105 int len) { | 105 int len) { |
106 HttpConnection* connection = FindConnection(socket); | 106 HttpConnection* connection = FindConnection(socket); |
107 DCHECK(connection != NULL); | 107 DCHECK(connection != NULL); |
108 if (connection == NULL) | 108 if (connection == NULL) |
109 return; | 109 return; |
110 | 110 |
111 connection->recv_data_.append(data, len); | 111 connection->recv_data_.append(data, len); |
112 while (connection->recv_data_.length()) { | 112 while (connection->recv_data_.length()) { |
113 if (connection->web_socket_.get()) { | 113 if (connection->web_socket_.get()) { |
(...skipping 27 matching lines...) Expand all Loading... |
141 delegate_->OnWebSocketRequest(connection->id(), request); | 141 delegate_->OnWebSocketRequest(connection->id(), request); |
142 connection->Shift(pos); | 142 connection->Shift(pos); |
143 continue; | 143 continue; |
144 } | 144 } |
145 // Request body is not supported. It is always empty. | 145 // Request body is not supported. It is always empty. |
146 delegate_->OnHttpRequest(connection->id(), request); | 146 delegate_->OnHttpRequest(connection->id(), request); |
147 connection->Shift(pos); | 147 connection->Shift(pos); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void HttpServer::DidClose(ListenSocket* socket) { | 151 void HttpServer::DidClose(StreamListenSocket* socket) { |
152 HttpConnection* connection = FindConnection(socket); | 152 HttpConnection* connection = FindConnection(socket); |
153 DCHECK(connection != NULL); | 153 DCHECK(connection != NULL); |
154 id_to_connection_.erase(connection->id()); | 154 id_to_connection_.erase(connection->id()); |
155 socket_to_connection_.erase(connection->socket_); | 155 socket_to_connection_.erase(connection->socket_); |
156 delete connection; | 156 delete connection; |
157 } | 157 } |
158 | 158 |
159 HttpServer::~HttpServer() { | 159 HttpServer::~HttpServer() { |
160 IdToConnectionMap copy = id_to_connection_; | 160 IdToConnectionMap copy = id_to_connection_; |
161 for (IdToConnectionMap::iterator it = copy.begin(); it != copy.end(); ++it) | 161 for (IdToConnectionMap::iterator it = copy.begin(); it != copy.end(); ++it) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 return false; | 295 return false; |
296 } | 296 } |
297 | 297 |
298 HttpConnection* HttpServer::FindConnection(int connection_id) { | 298 HttpConnection* HttpServer::FindConnection(int connection_id) { |
299 IdToConnectionMap::iterator it = id_to_connection_.find(connection_id); | 299 IdToConnectionMap::iterator it = id_to_connection_.find(connection_id); |
300 if (it == id_to_connection_.end()) | 300 if (it == id_to_connection_.end()) |
301 return NULL; | 301 return NULL; |
302 return it->second; | 302 return it->second; |
303 } | 303 } |
304 | 304 |
305 HttpConnection* HttpServer::FindConnection(ListenSocket* socket) { | 305 HttpConnection* HttpServer::FindConnection(StreamListenSocket* socket) { |
306 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); | 306 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); |
307 if (it == socket_to_connection_.end()) | 307 if (it == socket_to_connection_.end()) |
308 return NULL; | 308 return NULL; |
309 return it->second; | 309 return it->second; |
310 } | 310 } |
311 | 311 |
312 } // namespace net | 312 } // namespace net |
OLD | NEW |