| 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 "chrome_frame/test/test_server.h" | 5 #include "chrome_frame/test/test_server.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <objbase.h> | 8 #include <objbase.h> |
| 9 #include <urlmon.h> | 9 #include <urlmon.h> |
| 10 | 10 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 const net::StreamListenSocket* socket) const { | 191 const net::StreamListenSocket* socket) const { |
| 192 ConnectionList::const_iterator it; | 192 ConnectionList::const_iterator it; |
| 193 for (it = connections_.begin(); it != connections_.end(); it++) { | 193 for (it = connections_.begin(); it != connections_.end(); it++) { |
| 194 if ((*it)->IsSame(socket)) { | 194 if ((*it)->IsSame(socket)) { |
| 195 return (*it); | 195 return (*it); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 return NULL; | 198 return NULL; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void SimpleWebServer::DidAccept(net::StreamListenSocket* server, | 201 void SimpleWebServer::DidAccept( |
| 202 net::StreamListenSocket* connection) { | 202 net::StreamListenSocket* server, |
| 203 connections_.push_back(new Connection(connection)); | 203 scoped_ptr<net::StreamListenSocket> connection) { |
| 204 connections_.push_back(new Connection(connection.Pass())); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void SimpleWebServer::DidRead(net::StreamListenSocket* connection, | 207 void SimpleWebServer::DidRead(net::StreamListenSocket* connection, |
| 207 const char* data, | 208 const char* data, |
| 208 int len) { | 209 int len) { |
| 209 Connection* c = FindConnection(connection); | 210 Connection* c = FindConnection(connection); |
| 210 DCHECK(c); | 211 DCHECK(c); |
| 211 Request& r = c->request(); | 212 Request& r = c->request(); |
| 212 std::string str(data, len); | 213 std::string str(data, len); |
| 213 r.OnDataReceived(str); | 214 r.OnDataReceived(str); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 256 |
| 256 HTTPTestServer::HTTPTestServer(int port, const std::wstring& address, | 257 HTTPTestServer::HTTPTestServer(int port, const std::wstring& address, |
| 257 base::FilePath root_dir) | 258 base::FilePath root_dir) |
| 258 : port_(port), address_(address), root_dir_(root_dir) { | 259 : port_(port), address_(address), root_dir_(root_dir) { |
| 259 net::EnsureWinsockInit(); | 260 net::EnsureWinsockInit(); |
| 260 server_ = | 261 server_ = |
| 261 net::TCPListenSocket::CreateAndListen(WideToUTF8(address), port, this); | 262 net::TCPListenSocket::CreateAndListen(WideToUTF8(address), port, this); |
| 262 } | 263 } |
| 263 | 264 |
| 264 HTTPTestServer::~HTTPTestServer() { | 265 HTTPTestServer::~HTTPTestServer() { |
| 265 server_ = NULL; | |
| 266 } | 266 } |
| 267 | 267 |
| 268 std::list<scoped_refptr<ConfigurableConnection>>::iterator | 268 std::list<scoped_refptr<ConfigurableConnection>>::iterator |
| 269 HTTPTestServer::FindConnection(const net::StreamListenSocket* socket) { | 269 HTTPTestServer::FindConnection(const net::StreamListenSocket* socket) { |
| 270 ConnectionList::iterator it; | 270 ConnectionList::iterator it; |
| 271 // Scan through the list searching for the desired socket. Along the way, | 271 // Scan through the list searching for the desired socket. Along the way, |
| 272 // erase any connections for which the corresponding socket has already been | 272 // erase any connections for which the corresponding socket has already been |
| 273 // forgotten about as a result of all data having been sent. | 273 // forgotten about as a result of all data having been sent. |
| 274 for (it = connection_list_.begin(); it != connection_list_.end(); ) { | 274 for (it = connection_list_.begin(); it != connection_list_.end(); ) { |
| 275 ConfigurableConnection* connection = it->get(); | 275 ConfigurableConnection* connection = it->get(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 287 | 287 |
| 288 scoped_refptr<ConfigurableConnection> HTTPTestServer::ConnectionFromSocket( | 288 scoped_refptr<ConfigurableConnection> HTTPTestServer::ConnectionFromSocket( |
| 289 const net::StreamListenSocket* socket) { | 289 const net::StreamListenSocket* socket) { |
| 290 ConnectionList::iterator it = FindConnection(socket); | 290 ConnectionList::iterator it = FindConnection(socket); |
| 291 if (it != connection_list_.end()) | 291 if (it != connection_list_.end()) |
| 292 return *it; | 292 return *it; |
| 293 return NULL; | 293 return NULL; |
| 294 } | 294 } |
| 295 | 295 |
| 296 void HTTPTestServer::DidAccept(net::StreamListenSocket* server, | 296 void HTTPTestServer::DidAccept(net::StreamListenSocket* server, |
| 297 net::StreamListenSocket* socket) { | 297 scoped_ptr<net::StreamListenSocket> socket) { |
| 298 connection_list_.push_back(new ConfigurableConnection(socket)); | 298 connection_list_.push_back(new ConfigurableConnection(socket.Pass())); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void HTTPTestServer::DidRead(net::StreamListenSocket* socket, | 301 void HTTPTestServer::DidRead(net::StreamListenSocket* socket, |
| 302 const char* data, | 302 const char* data, |
| 303 int len) { | 303 int len) { |
| 304 scoped_refptr<ConfigurableConnection> connection = | 304 scoped_refptr<ConfigurableConnection> connection = |
| 305 ConnectionFromSocket(socket); | 305 ConnectionFromSocket(socket); |
| 306 if (connection) { | 306 if (connection) { |
| 307 std::string str(data, len); | 307 std::string str(data, len); |
| 308 connection->r_.OnDataReceived(str); | 308 connection->r_.OnDataReceived(str); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 socket_->Send(chunk_ptr, bytes_to_send); | 355 socket_->Send(chunk_ptr, bytes_to_send); |
| 356 VLOG(1) << "Sent(" << cur_pos_ << "," << bytes_to_send << "): " | 356 VLOG(1) << "Sent(" << cur_pos_ << "," << bytes_to_send << "): " |
| 357 << base::StringPiece(chunk_ptr, bytes_to_send); | 357 << base::StringPiece(chunk_ptr, bytes_to_send); |
| 358 | 358 |
| 359 cur_pos_ += bytes_to_send; | 359 cur_pos_ += bytes_to_send; |
| 360 if (cur_pos_ < size) { | 360 if (cur_pos_ < size) { |
| 361 base::MessageLoop::current()->PostDelayedTask( | 361 base::MessageLoop::current()->PostDelayedTask( |
| 362 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), | 362 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), |
| 363 base::TimeDelta::FromMilliseconds(options_.timeout_)); | 363 base::TimeDelta::FromMilliseconds(options_.timeout_)); |
| 364 } else { | 364 } else { |
| 365 socket_ = 0; // close the connection. | 365 Close(); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 | 368 |
| 369 void ConfigurableConnection::Close() { | 369 void ConfigurableConnection::Close() { |
| 370 socket_ = NULL; | 370 socket_.reset(); |
| 371 } | 371 } |
| 372 | 372 |
| 373 void ConfigurableConnection::Send(const std::string& headers, | 373 void ConfigurableConnection::Send(const std::string& headers, |
| 374 const std::string& content) { | 374 const std::string& content) { |
| 375 SendOptions options(SendOptions::IMMEDIATE, 0, 0); | 375 SendOptions options(SendOptions::IMMEDIATE, 0, 0); |
| 376 SendWithOptions(headers, content, options); | 376 SendWithOptions(headers, content, options); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void ConfigurableConnection::SendWithOptions(const std::string& headers, | 379 void ConfigurableConnection::SendWithOptions(const std::string& headers, |
| 380 const std::string& content, | 380 const std::string& content, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 data_.append(content_length_header); | 413 data_.append(content_length_header); |
| 414 data_.append("\r\n"); | 414 data_.append("\r\n"); |
| 415 } | 415 } |
| 416 | 416 |
| 417 base::MessageLoop::current()->PostDelayedTask( | 417 base::MessageLoop::current()->PostDelayedTask( |
| 418 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), | 418 FROM_HERE, base::Bind(&ConfigurableConnection::SendChunk, this), |
| 419 base::TimeDelta::FromMilliseconds(options.timeout_)); | 419 base::TimeDelta::FromMilliseconds(options.timeout_)); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace test_server | 422 } // namespace test_server |
| OLD | NEW |