Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: net/server/http_server.cc

Issue 10161005: Add DefaultListenSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Matt's comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return true; 205 return true;
206 case ST_ERR: 206 case ST_ERR:
207 return false; 207 return false;
208 } 208 }
209 } 209 }
210 } 210 }
211 // No more characters, but we haven't finished parsing yet. 211 // No more characters, but we haven't finished parsing yet.
212 return false; 212 return false;
213 } 213 }
214 214
215 void HttpServer::DidAccept(ListenSocket* server, 215 void HttpServer::DidAccept(StreamListenSocket* server,
216 ListenSocket* socket) { 216 StreamListenSocket* socket) {
217 HttpConnection* connection = new HttpConnection(this, socket); 217 HttpConnection* connection = new HttpConnection(this, socket);
218 id_to_connection_[connection->id()] = connection; 218 id_to_connection_[connection->id()] = connection;
219 socket_to_connection_[socket] = connection; 219 socket_to_connection_[socket] = connection;
220 } 220 }
221 221
222 void HttpServer::DidRead(ListenSocket* socket, 222 void HttpServer::DidRead(StreamListenSocket* socket,
223 const char* data, 223 const char* data,
224 int len) { 224 int len) {
225 HttpConnection* connection = FindConnection(socket); 225 HttpConnection* connection = FindConnection(socket);
226 DCHECK(connection != NULL); 226 DCHECK(connection != NULL);
227 if (connection == NULL) 227 if (connection == NULL)
228 return; 228 return;
229 229
230 connection->recv_data_.append(data, len); 230 connection->recv_data_.append(data, len);
231 while (connection->recv_data_.length()) { 231 while (connection->recv_data_.length()) {
232 if (connection->web_socket_.get()) { 232 if (connection->web_socket_.get()) {
(...skipping 27 matching lines...) Expand all
260 delegate_->OnWebSocketRequest(connection->id(), request); 260 delegate_->OnWebSocketRequest(connection->id(), request);
261 connection->Shift(pos); 261 connection->Shift(pos);
262 continue; 262 continue;
263 } 263 }
264 // Request body is not supported. It is always empty. 264 // Request body is not supported. It is always empty.
265 delegate_->OnHttpRequest(connection->id(), request); 265 delegate_->OnHttpRequest(connection->id(), request);
266 connection->Shift(pos); 266 connection->Shift(pos);
267 } 267 }
268 } 268 }
269 269
270 void HttpServer::DidClose(ListenSocket* socket) { 270 void HttpServer::DidClose(StreamListenSocket* socket) {
271 HttpConnection* connection = FindConnection(socket); 271 HttpConnection* connection = FindConnection(socket);
272 DCHECK(connection != NULL); 272 DCHECK(connection != NULL);
273 id_to_connection_.erase(connection->id()); 273 id_to_connection_.erase(connection->id());
274 socket_to_connection_.erase(connection->socket_); 274 socket_to_connection_.erase(connection->socket_);
275 delete connection; 275 delete connection;
276 } 276 }
277 277
278 HttpConnection* HttpServer::FindConnection(int connection_id) { 278 HttpConnection* HttpServer::FindConnection(int connection_id) {
279 IdToConnectionMap::iterator it = id_to_connection_.find(connection_id); 279 IdToConnectionMap::iterator it = id_to_connection_.find(connection_id);
280 if (it == id_to_connection_.end()) 280 if (it == id_to_connection_.end())
281 return NULL; 281 return NULL;
282 return it->second; 282 return it->second;
283 } 283 }
284 284
285 HttpConnection* HttpServer::FindConnection(ListenSocket* socket) { 285 HttpConnection* HttpServer::FindConnection(StreamListenSocket* socket) {
286 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket); 286 SocketToConnectionMap::iterator it = socket_to_connection_.find(socket);
287 if (it == socket_to_connection_.end()) 287 if (it == socket_to_connection_.end())
288 return NULL; 288 return NULL;
289 return it->second; 289 return it->second;
290 } 290 }
291 291
292 void HttpServer::AcceptWebSocket( 292 void HttpServer::AcceptWebSocket(
293 int connection_id, 293 int connection_id,
294 const HttpServerRequestInfo& request) { 294 const HttpServerRequestInfo& request) {
295 HttpConnection* connection = FindConnection(connection_id); 295 HttpConnection* connection = FindConnection(connection_id);
296 if (connection == NULL) 296 if (connection == NULL)
297 return; 297 return;
298 298
299 DCHECK(connection->web_socket_.get()); 299 DCHECK(connection->web_socket_.get());
300 connection->web_socket_->Accept(request); 300 connection->web_socket_->Accept(request);
301 } 301 }
302 302
303 void HttpServer::SendOverWebSocket(int connection_id, 303 void HttpServer::SendOverWebSocket(int connection_id,
304 const std::string& data) { 304 const std::string& data) {
305 HttpConnection* connection = FindConnection(connection_id); 305 HttpConnection* connection = FindConnection(connection_id);
306 if (connection == NULL) 306 if (connection == NULL)
307 return; 307 return;
308 DCHECK(connection->web_socket_.get()); 308 DCHECK(connection->web_socket_.get());
309 connection->web_socket_->Send(data); 309 connection->web_socket_->Send(data);
310 } 310 }
311 311
312 } // namespace net 312 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698