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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 146 |
147 int HttpServer::HandleAcceptResult(int rv) { | 147 int HttpServer::HandleAcceptResult(int rv) { |
148 if (rv < 0) { | 148 if (rv < 0) { |
149 LOG(ERROR) << "Accept error: rv=" << rv; | 149 LOG(ERROR) << "Accept error: rv=" << rv; |
150 return rv; | 150 return rv; |
151 } | 151 } |
152 | 152 |
153 HttpConnection* connection = | 153 HttpConnection* connection = |
154 new HttpConnection(++last_id_, accepted_socket_.Pass()); | 154 new HttpConnection(++last_id_, accepted_socket_.Pass()); |
155 id_to_connection_[connection->id()] = connection; | 155 id_to_connection_[connection->id()] = connection; |
156 DoReadLoop(connection); | 156 delegate_->OnConnect(connection->id()); |
| 157 if (!HasClosedConnection(connection)) |
| 158 DoReadLoop(connection); |
157 return OK; | 159 return OK; |
158 } | 160 } |
159 | 161 |
160 void HttpServer::DoReadLoop(HttpConnection* connection) { | 162 void HttpServer::DoReadLoop(HttpConnection* connection) { |
161 int rv; | 163 int rv; |
162 do { | 164 do { |
163 HttpConnection::ReadIOBuffer* read_buf = connection->read_buf(); | 165 HttpConnection::ReadIOBuffer* read_buf = connection->read_buf(); |
164 // Increases read buffer size if necessary. | 166 // Increases read buffer size if necessary. |
165 if (read_buf->RemainingCapacity() == 0 && !read_buf->IncreaseCapacity()) { | 167 if (read_buf->RemainingCapacity() == 0 && !read_buf->IncreaseCapacity()) { |
166 Close(connection->id()); | 168 Close(connection->id()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 455 |
454 // This is called after any delegate callbacks are called to check if Close() | 456 // This is called after any delegate callbacks are called to check if Close() |
455 // has been called during callback processing. Using the pointer of connection, | 457 // has been called during callback processing. Using the pointer of connection, |
456 // |connection| is safe here because Close() deletes the connection in next run | 458 // |connection| is safe here because Close() deletes the connection in next run |
457 // loop. | 459 // loop. |
458 bool HttpServer::HasClosedConnection(HttpConnection* connection) { | 460 bool HttpServer::HasClosedConnection(HttpConnection* connection) { |
459 return FindConnection(connection->id()) != connection; | 461 return FindConnection(connection->id()) != connection; |
460 } | 462 } |
461 | 463 |
462 } // namespace net | 464 } // namespace net |
OLD | NEW |