summaryrefslogtreecommitdiffstats
path: root/net/server/http_server.cc
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-28 09:29:28 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-28 09:29:28 +0000
commita981330295415845ef13cd85afeff42032d782df (patch)
tree46ad72c4cabd094a5f4dea2faa1bde6fb7d3677f /net/server/http_server.cc
parent20eef6d14fce11a57949d052db064e56242c4c82 (diff)
downloadchromium_src-a981330295415845ef13cd85afeff42032d782df.zip
chromium_src-a981330295415845ef13cd85afeff42032d782df.tar.gz
chromium_src-a981330295415845ef13cd85afeff42032d782df.tar.bz2
RefCounted types should not have public destructors, net/
BUG=123295 TEST=none Review URL: http://codereview.chromium.org/10066045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134460 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/server/http_server.cc')
-rw-r--r--net/server/http_server.cc176
1 files changed, 88 insertions, 88 deletions
diff --git a/net/server/http_server.cc b/net/server/http_server.cc
index ad1fa6e..c9d8ac75 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -24,12 +24,24 @@ HttpServer::HttpServer(const std::string& host,
server_ = TCPListenSocket::CreateAndListen(host, port, this);
}
-HttpServer::~HttpServer() {
- IdToConnectionMap copy = id_to_connection_;
- for (IdToConnectionMap::iterator it = copy.begin(); it != copy.end(); ++it)
- delete it->second;
+void HttpServer::AcceptWebSocket(
+ int connection_id,
+ const HttpServerRequestInfo& request) {
+ HttpConnection* connection = FindConnection(connection_id);
+ if (connection == NULL)
+ return;
- server_ = NULL;
+ DCHECK(connection->web_socket_.get());
+ connection->web_socket_->Accept(request);
+}
+
+void HttpServer::SendOverWebSocket(int connection_id,
+ const std::string& data) {
+ HttpConnection* connection = FindConnection(connection_id);
+ if (connection == NULL)
+ return;
+ DCHECK(connection->web_socket_.get());
+ connection->web_socket_->Send(data);
}
void HttpServer::Send(int connection_id, const std::string& data) {
@@ -81,6 +93,77 @@ void HttpServer::Close(int connection_id)
DidClose(connection->socket_);
}
+void HttpServer::DidAccept(ListenSocket* server,
+ ListenSocket* socket) {
+ HttpConnection* connection = new HttpConnection(this, socket);
+ id_to_connection_[connection->id()] = connection;
+ socket_to_connection_[socket] = connection;
+}
+
+void HttpServer::DidRead(ListenSocket* socket,
+ const char* data,
+ int len) {
+ HttpConnection* connection = FindConnection(socket);
+ DCHECK(connection != NULL);
+ if (connection == NULL)
+ return;
+
+ connection->recv_data_.append(data, len);
+ while (connection->recv_data_.length()) {
+ if (connection->web_socket_.get()) {
+ std::string message;
+ WebSocket::ParseResult result = connection->web_socket_->Read(&message);
+ if (result == WebSocket::FRAME_INCOMPLETE)
+ break;
+
+ if (result == WebSocket::FRAME_CLOSE ||
+ result == WebSocket::FRAME_ERROR) {
+ Close(connection->id());
+ break;
+ }
+ delegate_->OnWebSocketMessage(connection->id(), message);
+ continue;
+ }
+
+ HttpServerRequestInfo request;
+ size_t pos = 0;
+ if (!ParseHeaders(connection, &request, &pos))
+ break;
+
+ std::string connection_header = request.GetHeaderValue("Connection");
+ if (connection_header == "Upgrade") {
+ connection->web_socket_.reset(WebSocket::CreateWebSocket(connection,
+ request,
+ &pos));
+
+ if (!connection->web_socket_.get()) // Not enought data was received.
+ break;
+ delegate_->OnWebSocketRequest(connection->id(), request);
+ connection->Shift(pos);
+ continue;
+ }
+ // Request body is not supported. It is always empty.
+ delegate_->OnHttpRequest(connection->id(), request);
+ connection->Shift(pos);
+ }
+}
+
+void HttpServer::DidClose(ListenSocket* socket) {
+ HttpConnection* connection = FindConnection(socket);
+ DCHECK(connection != NULL);
+ id_to_connection_.erase(connection->id());
+ socket_to_connection_.erase(connection->socket_);
+ delete connection;
+}
+
+HttpServer::~HttpServer() {
+ IdToConnectionMap copy = id_to_connection_;
+ for (IdToConnectionMap::iterator it = copy.begin(); it != copy.end(); ++it)
+ delete it->second;
+
+ server_ = NULL;
+}
+
//
// HTTP Request Parser
// This HTTP request parser uses a simple state machine to quickly parse
@@ -212,69 +295,6 @@ bool HttpServer::ParseHeaders(HttpConnection* connection,
return false;
}
-void HttpServer::DidAccept(ListenSocket* server,
- ListenSocket* socket) {
- HttpConnection* connection = new HttpConnection(this, socket);
- id_to_connection_[connection->id()] = connection;
- socket_to_connection_[socket] = connection;
-}
-
-void HttpServer::DidRead(ListenSocket* socket,
- const char* data,
- int len) {
- HttpConnection* connection = FindConnection(socket);
- DCHECK(connection != NULL);
- if (connection == NULL)
- return;
-
- connection->recv_data_.append(data, len);
- while (connection->recv_data_.length()) {
- if (connection->web_socket_.get()) {
- std::string message;
- WebSocket::ParseResult result = connection->web_socket_->Read(&message);
- if (result == WebSocket::FRAME_INCOMPLETE)
- break;
-
- if (result == WebSocket::FRAME_CLOSE ||
- result == WebSocket::FRAME_ERROR) {
- Close(connection->id());
- break;
- }
- delegate_->OnWebSocketMessage(connection->id(), message);
- continue;
- }
-
- HttpServerRequestInfo request;
- size_t pos = 0;
- if (!ParseHeaders(connection, &request, &pos))
- break;
-
- std::string connection_header = request.GetHeaderValue("Connection");
- if (connection_header == "Upgrade") {
- connection->web_socket_.reset(WebSocket::CreateWebSocket(connection,
- request,
- &pos));
-
- if (!connection->web_socket_.get()) // Not enought data was received.
- break;
- delegate_->OnWebSocketRequest(connection->id(), request);
- connection->Shift(pos);
- continue;
- }
- // Request body is not supported. It is always empty.
- delegate_->OnHttpRequest(connection->id(), request);
- connection->Shift(pos);
- }
-}
-
-void HttpServer::DidClose(ListenSocket* socket) {
- HttpConnection* connection = FindConnection(socket);
- DCHECK(connection != NULL);
- id_to_connection_.erase(connection->id());
- socket_to_connection_.erase(connection->socket_);
- delete connection;
-}
-
HttpConnection* HttpServer::FindConnection(int connection_id) {
IdToConnectionMap::iterator it = id_to_connection_.find(connection_id);
if (it == id_to_connection_.end())
@@ -289,24 +309,4 @@ HttpConnection* HttpServer::FindConnection(ListenSocket* socket) {
return it->second;
}
-void HttpServer::AcceptWebSocket(
- int connection_id,
- const HttpServerRequestInfo& request) {
- HttpConnection* connection = FindConnection(connection_id);
- if (connection == NULL)
- return;
-
- DCHECK(connection->web_socket_.get());
- connection->web_socket_->Accept(request);
-}
-
-void HttpServer::SendOverWebSocket(int connection_id,
- const std::string& data) {
- HttpConnection* connection = FindConnection(connection_id);
- if (connection == NULL)
- return;
- DCHECK(connection->web_socket_.get());
- connection->web_socket_->Send(data);
-}
-
} // namespace net