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

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

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 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
« no previous file with comments | « net/sdch/sdch_owner_unittest.cc ('k') | net/server/http_server_request_info.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/stl_util.h" 11 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
16 #include "base/sys_byteorder.h" 15 #include "base/sys_byteorder.h"
16 #include "base/thread_task_runner_handle.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/server/http_connection.h" 19 #include "net/server/http_connection.h"
20 #include "net/server/http_server_request_info.h" 20 #include "net/server/http_server_request_info.h"
21 #include "net/server/http_server_response_info.h" 21 #include "net/server/http_server_response_info.h"
22 #include "net/server/web_socket.h" 22 #include "net/server/web_socket.h"
23 #include "net/socket/server_socket.h" 23 #include "net/socket/server_socket.h"
24 #include "net/socket/stream_socket.h" 24 #include "net/socket/stream_socket.h"
25 #include "net/socket/tcp_server_socket.h" 25 #include "net/socket/tcp_server_socket.h"
26 26
27 namespace net { 27 namespace net {
28 28
29 HttpServer::HttpServer(scoped_ptr<ServerSocket> server_socket, 29 HttpServer::HttpServer(scoped_ptr<ServerSocket> server_socket,
30 HttpServer::Delegate* delegate) 30 HttpServer::Delegate* delegate)
31 : server_socket_(server_socket.Pass()), 31 : server_socket_(server_socket.Pass()),
32 delegate_(delegate), 32 delegate_(delegate),
33 last_id_(0), 33 last_id_(0),
34 weak_ptr_factory_(this) { 34 weak_ptr_factory_(this) {
35 DCHECK(server_socket_); 35 DCHECK(server_socket_);
36 // Start accepting connections in next run loop in case when delegate is not 36 // Start accepting connections in next run loop in case when delegate is not
37 // ready to get callbacks. 37 // ready to get callbacks.
38 base::MessageLoopProxy::current()->PostTask( 38 base::ThreadTaskRunnerHandle::Get()->PostTask(
39 FROM_HERE, 39 FROM_HERE,
40 base::Bind(&HttpServer::DoAcceptLoop, weak_ptr_factory_.GetWeakPtr())); 40 base::Bind(&HttpServer::DoAcceptLoop, weak_ptr_factory_.GetWeakPtr()));
41 } 41 }
42 42
43 HttpServer::~HttpServer() { 43 HttpServer::~HttpServer() {
44 STLDeleteContainerPairSecondPointers( 44 STLDeleteContainerPairSecondPointers(
45 id_to_connection_.begin(), id_to_connection_.end()); 45 id_to_connection_.begin(), id_to_connection_.end());
46 } 46 }
47 47
48 void HttpServer::AcceptWebSocket( 48 void HttpServer::AcceptWebSocket(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 if (connection == NULL) 108 if (connection == NULL)
109 return; 109 return;
110 110
111 id_to_connection_.erase(connection_id); 111 id_to_connection_.erase(connection_id);
112 delegate_->OnClose(connection_id); 112 delegate_->OnClose(connection_id);
113 113
114 // The call stack might have callbacks which still have the pointer of 114 // The call stack might have callbacks which still have the pointer of
115 // connection. Instead of referencing connection with ID all the time, 115 // connection. Instead of referencing connection with ID all the time,
116 // destroys the connection in next run loop to make sure any pending 116 // destroys the connection in next run loop to make sure any pending
117 // callbacks in the call stack return. 117 // callbacks in the call stack return.
118 base::MessageLoopProxy::current()->DeleteSoon(FROM_HERE, connection); 118 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, connection);
119 } 119 }
120 120
121 int HttpServer::GetLocalAddress(IPEndPoint* address) { 121 int HttpServer::GetLocalAddress(IPEndPoint* address) {
122 return server_socket_->GetLocalAddress(address); 122 return server_socket_->GetLocalAddress(address);
123 } 123 }
124 124
125 void HttpServer::SetReceiveBufferSize(int connection_id, int32 size) { 125 void HttpServer::SetReceiveBufferSize(int connection_id, int32 size) {
126 HttpConnection* connection = FindConnection(connection_id); 126 HttpConnection* connection = FindConnection(connection_id);
127 if (connection) 127 if (connection)
128 connection->read_buf()->set_max_buffer_size(size); 128 connection->read_buf()->set_max_buffer_size(size);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 462
463 // This is called after any delegate callbacks are called to check if Close() 463 // This is called after any delegate callbacks are called to check if Close()
464 // has been called during callback processing. Using the pointer of connection, 464 // has been called during callback processing. Using the pointer of connection,
465 // |connection| is safe here because Close() deletes the connection in next run 465 // |connection| is safe here because Close() deletes the connection in next run
466 // loop. 466 // loop.
467 bool HttpServer::HasClosedConnection(HttpConnection* connection) { 467 bool HttpServer::HasClosedConnection(HttpConnection* connection) {
468 return FindConnection(connection->id()) != connection; 468 return FindConnection(connection->id()) != connection;
469 } 469 }
470 470
471 } // namespace net 471 } // namespace net
OLDNEW
« no previous file with comments | « net/sdch/sdch_owner_unittest.cc ('k') | net/server/http_server_request_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698