From d2ec57057e591810ebbb5febb34ae0cadf5068c5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 23 Jun 2013 23:44:38 +0900 Subject: [PATCH] HttpServer: Use std::unique_ptr for lastBody_ and headerProcessor_ --- src/HttpServer.cc | 7 ++++++- src/HttpServer.h | 9 +++------ src/HttpServerBodyCommand.cc | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index bdfc093c..d94da365 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -61,7 +61,7 @@ HttpServer::HttpServer(const std::shared_ptr& socket) : socket_(socket), socketRecvBuffer_(new SocketRecvBuffer(socket_)), socketBuffer_(socket), - headerProcessor_(new HttpHeaderProcessor + headerProcessor_(make_unique (HttpHeaderProcessor::SERVER_PARSER)), lastContentLength_(0), bodyConsumed_(0), @@ -382,6 +382,11 @@ std::string HttpServer::createQuery() const } } +DiskWriter* HttpServer::getBody() const +{ + return lastBody_.get(); +} + bool HttpServer::supportsPersistentConnection() const { return keepAlive_ && diff --git a/src/HttpServer.h b/src/HttpServer.h index 8caa0b68..c0c8069d 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -67,14 +67,14 @@ private: std::shared_ptr socket_; std::shared_ptr socketRecvBuffer_; SocketBuffer socketBuffer_; - std::shared_ptr headerProcessor_; + std::unique_ptr headerProcessor_; std::shared_ptr lastRequestHeader_; int64_t lastContentLength_; // How many bytes are consumed. The total number of bytes is // lastContentLength_. int64_t bodyConsumed_; RequestType reqType_; - std::shared_ptr lastBody_; + std::unique_ptr lastBody_; bool keepAlive_; bool gzip_; std::string username_; @@ -101,10 +101,7 @@ public: std::string createQuery() const; - const std::shared_ptr& getBody() const - { - return lastBody_; - } + DiskWriter* getBody() const; RequestType getRequestType() const { diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index d782fe9f..dca204ec 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -210,7 +210,7 @@ bool HttpServerBodyCommand::execute() switch(httpServer_->getRequestType()) { case RPC_TYPE_XML: { #ifdef ENABLE_XML_RPC - auto dw = std::static_pointer_cast + auto dw = static_cast (httpServer_->getBody()); int error; error = dw->finalize(); @@ -255,7 +255,7 @@ bool HttpServerBodyCommand::execute() param.request.size(), error); } else { - auto dw = std::static_pointer_cast + auto dw = static_cast (httpServer_->getBody()); error = dw->finalize(); if(error == 0) {