diff options
-rw-r--r-- | net/server/http_server.cc | 9 | ||||
-rw-r--r-- | net/server/http_server.h | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/net/server/http_server.cc b/net/server/http_server.cc index 87b50fa..dd4ef8e 100644 --- a/net/server/http_server.cc +++ b/net/server/http_server.cc @@ -183,14 +183,16 @@ void HttpServer::Close(int connection_id) connection->DetachSocket(); } -HttpServer::Connection::Connection(ListenSocket* sock) - : socket_(sock), +HttpServer::Connection::Connection(HttpServer* server, ListenSocket* sock) + : server_(server), + socket_(sock), is_web_socket_(false) { id_ = lastId_++; } HttpServer::Connection::~Connection() { DetachSocket(); + server_->delegate_->OnClose(id_); } void HttpServer::Connection::DetachSocket() { @@ -353,7 +355,7 @@ bool HttpServer::ParseHeaders(Connection* connection, void HttpServer::DidAccept(ListenSocket* server, ListenSocket* socket) { - Connection* connection = new Connection(socket); + Connection* connection = new Connection(this, socket); id_to_connection_[connection->id_] = connection; socket_to_connection_[socket] = connection; } @@ -395,7 +397,6 @@ void HttpServer::DidRead(ListenSocket* socket, void HttpServer::DidClose(ListenSocket* socket) { Connection* connection = FindConnection(socket); DCHECK(connection != NULL); - delegate_->OnClose(connection->id_); id_to_connection_.erase(connection->id_); socket_to_connection_.erase(connection->socket_); delete connection; diff --git a/net/server/http_server.h b/net/server/http_server.h index fc87cdb..bee6e28 100644 --- a/net/server/http_server.h +++ b/net/server/http_server.h @@ -56,11 +56,12 @@ private: static int lastId_; friend class HttpServer; - explicit Connection(ListenSocket* sock); + explicit Connection(HttpServer* server, ListenSocket* sock); ~Connection(); void DetachSocket(); + HttpServer* server_; scoped_refptr<ListenSocket> socket_; bool is_web_socket_; std::string recv_data_; @@ -68,6 +69,7 @@ private: DISALLOW_COPY_AND_ASSIGN(Connection); }; + friend class Connection; // ListenSocketDelegate |