From 36633f403b4ba6c5f592bc65d387869aa5403fc1 Mon Sep 17 00:00:00 2001 From: "pliard@chromium.org" Date: Wed, 16 May 2012 09:22:30 +0000 Subject: Refactor TCPListenSocket. This is part of Chrome for Android upstreaming. This CL adds a common base class, StreamListenSocket, providing a default implementation inherited by TCPListenSocket and the upcoming UnixDomainSocket. That lets us share the common code used by both TCPListenSocket and UnixDomainSocket. This also removes the recently introduced ListenSocket class which is unnecessary now we have StreamListenSocket. TEST=net_unittests Review URL: https://chromiumcodereview.appspot.com/10161005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137387 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/test/test_server.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'chrome_frame/test/test_server.cc') diff --git a/chrome_frame/test/test_server.cc b/chrome_frame/test/test_server.cc index b38b143..5eaf06f 100644 --- a/chrome_frame/test/test_server.cc +++ b/chrome_frame/test/test_server.cc @@ -75,6 +75,12 @@ void Request::OnDataReceived(const std::string& data) { } } +ResponseForPath::~ResponseForPath() { +} + +SimpleResponse::~SimpleResponse() { +} + bool FileResponse::GetContentType(std::string* content_type) const { size_t length = ContentLength(); char buffer[4096]; @@ -100,7 +106,7 @@ bool FileResponse::GetContentType(std::string* content_type) const { return content_type->length() > 0; } -void FileResponse::WriteContents(net::ListenSocket* socket) const { +void FileResponse::WriteContents(net::StreamListenSocket* socket) const { DCHECK(file_.get()); if (file_.get()) { socket->Send(reinterpret_cast(file_->data()), @@ -168,7 +174,7 @@ Response* SimpleWebServer::FindResponse(const Request& request) const { } Connection* SimpleWebServer::FindConnection( - const net::ListenSocket* socket) const { + const net::StreamListenSocket* socket) const { ConnectionList::const_iterator it; for (it = connections_.begin(); it != connections_.end(); it++) { if ((*it)->IsSame(socket)) { @@ -178,12 +184,12 @@ Connection* SimpleWebServer::FindConnection( return NULL; } -void SimpleWebServer::DidAccept(net::ListenSocket* server, - net::ListenSocket* connection) { +void SimpleWebServer::DidAccept(net::StreamListenSocket* server, + net::StreamListenSocket* connection) { connections_.push_back(new Connection(connection)); } -void SimpleWebServer::DidRead(net::ListenSocket* connection, +void SimpleWebServer::DidRead(net::StreamListenSocket* connection, const char* data, int len) { Connection* c = FindConnection(connection); @@ -220,7 +226,7 @@ void SimpleWebServer::DidRead(net::ListenSocket* connection, } } -void SimpleWebServer::DidClose(net::ListenSocket* sock) { +void SimpleWebServer::DidClose(net::StreamListenSocket* sock) { // To keep the historical list of connections reasonably tidy, we delete // 404's when the connection ends. Connection* c = FindConnection(sock); @@ -246,7 +252,7 @@ HTTPTestServer::~HTTPTestServer() { } std::list>::iterator -HTTPTestServer::FindConnection(const net::ListenSocket* socket) { +HTTPTestServer::FindConnection(const net::StreamListenSocket* socket) { ConnectionList::iterator it; // Scan through the list searching for the desired socket. Along the way, // erase any connections for which the corresponding socket has already been @@ -266,19 +272,19 @@ HTTPTestServer::FindConnection(const net::ListenSocket* socket) { } scoped_refptr HTTPTestServer::ConnectionFromSocket( - const net::ListenSocket* socket) { + const net::StreamListenSocket* socket) { ConnectionList::iterator it = FindConnection(socket); if (it != connection_list_.end()) return *it; return NULL; } -void HTTPTestServer::DidAccept(net::ListenSocket* server, - net::ListenSocket* socket) { +void HTTPTestServer::DidAccept(net::StreamListenSocket* server, + net::StreamListenSocket* socket) { connection_list_.push_back(new ConfigurableConnection(socket)); } -void HTTPTestServer::DidRead(net::ListenSocket* socket, +void HTTPTestServer::DidRead(net::StreamListenSocket* socket, const char* data, int len) { scoped_refptr connection = @@ -298,7 +304,7 @@ void HTTPTestServer::DidRead(net::ListenSocket* socket, } } -void HTTPTestServer::DidClose(net::ListenSocket* socket) { +void HTTPTestServer::DidClose(net::StreamListenSocket* socket) { ConnectionList::iterator it = FindConnection(socket); if (it != connection_list_.end()) connection_list_.erase(it); @@ -373,8 +379,8 @@ void ConfigurableConnection::SendWithOptions(const std::string& headers, socket_->Send(headers); socket_->Send(content_length_header, true); socket_->Send(content); - // Post a task to close the socket since ListenSocket doesn't like instances - // to go away from within its callbacks. + // Post a task to close the socket since StreamListenSocket doesn't like + // instances to go away from within its callbacks. MessageLoop::current()->PostTask( FROM_HERE, base::Bind(&ConfigurableConnection::Close, this)); -- cgit v1.1