From fba7e7ee8b8339c9709c1fe9d07279df07781af3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 23 Jun 2013 23:31:07 +0900 Subject: [PATCH] Use move to send string data into SocketBuffer::pushStr --- src/FtpConnection.cc | 26 +++++++++++++------------- src/HttpConnection.cc | 4 ++-- src/HttpServer.cc | 31 ++++++++++++++++--------------- src/HttpServer.h | 4 ++-- src/HttpServerBodyCommand.cc | 8 ++++---- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 7e773cd2..49e1baa2 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -85,7 +85,7 @@ bool FtpConnection::sendUser() request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, "USER ********")); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -99,7 +99,7 @@ bool FtpConnection::sendPass() request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, "PASS ********")); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -113,7 +113,7 @@ bool FtpConnection::sendType() request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_,request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -125,7 +125,7 @@ bool FtpConnection::sendPwd() std::string request = "PWD\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_,request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -139,7 +139,7 @@ bool FtpConnection::sendCwd(const std::string& dir) request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_,request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -154,7 +154,7 @@ bool FtpConnection::sendMdtm() request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -169,7 +169,7 @@ bool FtpConnection::sendSize() request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -181,7 +181,7 @@ bool FtpConnection::sendEpsv() std::string request("EPSV\r\n"); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -193,7 +193,7 @@ bool FtpConnection::sendPasv() std::string request("PASV\r\n"); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -223,7 +223,7 @@ bool FtpConnection::sendEprt(const std::shared_ptr& serverSocket) addrinfo.first.c_str(), addrinfo.second); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -243,7 +243,7 @@ bool FtpConnection::sendPort(const std::shared_ptr& serverSocket) addrinfo.second/256, addrinfo.second%256); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -258,7 +258,7 @@ bool FtpConnection::sendRest(const std::shared_ptr& segment) segment->getPositionToWrite() : static_cast(0LL)); A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); @@ -273,7 +273,7 @@ bool FtpConnection::sendRetr() request += "\r\n"; A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); } socketBuffer_.send(); return socketBuffer_.sendBufferIsEmpty(); diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc index 78fe8164..df117c1e 100644 --- a/src/HttpConnection.cc +++ b/src/HttpConnection.cc @@ -105,7 +105,7 @@ void HttpConnection::sendRequest(const std::shared_ptr& httpRequest A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, eraseConfidentialInfo(request).c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); socketBuffer_.send(); std::shared_ptr entry(new HttpRequestEntry(httpRequest)); outstandingHttpRequests_.push_back(entry); @@ -118,7 +118,7 @@ void HttpConnection::sendProxyRequest A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, eraseConfidentialInfo(request).c_str())); - socketBuffer_.pushStr(request); + socketBuffer_.pushStr(std::move(request)); socketBuffer_.send(); std::shared_ptr entry(new HttpRequestEntry(httpRequest)); outstandingHttpRequests_.push_back(entry); diff --git a/src/HttpServer.cc b/src/HttpServer.cc index f314ee1e..bdfc093c 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -210,26 +210,27 @@ const std::string& HttpServer::getRequestPath() const return lastRequestHeader_->getRequestPath(); } -void HttpServer::feedResponse(std::string& text, const std::string& contentType) +void HttpServer::feedResponse(std::string text, + const std::string& contentType) { - feedResponse(200, "", text, contentType); + feedResponse(200, "", std::move(text), contentType); } void HttpServer::feedResponse(int status, const std::string& headers, - const std::string& text, + std::string text, const std::string& contentType) { std::string httpDate = Time().toHTTPDate(); - std::string header= fmt("HTTP/1.1 %s\r\n" - "Date: %s\r\n" - "Content-Length: %lu\r\n" - "Expires: %s\r\n" - "Cache-Control: no-cache\r\n", - getStatusString(status), - httpDate.c_str(), - static_cast(text.size()), - httpDate.c_str()); + std::string header = fmt("HTTP/1.1 %s\r\n" + "Date: %s\r\n" + "Content-Length: %lu\r\n" + "Expires: %s\r\n" + "Cache-Control: no-cache\r\n", + getStatusString(status), + httpDate.c_str(), + static_cast(text.size()), + httpDate.c_str()); if(!contentType.empty()) { header += "Content-Type: "; header += contentType; @@ -249,8 +250,8 @@ void HttpServer::feedResponse(int status, header += headers; header += "\r\n"; A2_LOG_DEBUG(fmt("HTTP Server sends response:\n%s", header.c_str())); - socketBuffer_.pushStr(header); - socketBuffer_.pushStr(text); + socketBuffer_.pushStr(std::move(header)); + socketBuffer_.pushStr(std::move(text)); } void HttpServer::feedUpgradeResponse(const std::string& protocol, @@ -264,7 +265,7 @@ void HttpServer::feedUpgradeResponse(const std::string& protocol, protocol.c_str(), headers.c_str()); A2_LOG_DEBUG(fmt("HTTP Server sends upgrade response:\n%s", header.c_str())); - socketBuffer_.pushStr(header); + socketBuffer_.pushStr(std::move(header)); } ssize_t HttpServer::sendResponse() diff --git a/src/HttpServer.h b/src/HttpServer.h index 8f07412a..8caa0b68 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -111,7 +111,7 @@ public: return reqType_; } - void feedResponse(std::string& text, const std::string& contentType); + void feedResponse(std::string text, const std::string& contentType); // Feeds HTTP response with the status code |status| (e.g., // 200). The |headers| is zero or more lines of HTTP header field @@ -119,7 +119,7 @@ public: // body. The |contentType" is the content-type of the response body. void feedResponse(int status, const std::string& headers = "", - const std::string& text = "", + std::string text = "", const std::string& contentType = ""); // Feeds "101 Switching Protocols" response. The |protocol| will diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index b05b6766..d782fe9f 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -107,7 +107,7 @@ void HttpServerBodyCommand::sendJsonRpcResponse bool gzip = httpServer_->supportsGZip(); std::string responseData = rpc::toJson(res, callback, gzip); if(res.code == 0) { - httpServer_->feedResponse(responseData, + httpServer_->feedResponse(std::move(responseData), getJsonRpcContentType(!callback.empty())); } else { httpServer_->disableKeepAlive(); @@ -123,7 +123,7 @@ void HttpServerBodyCommand::sendJsonRpcResponse httpCode = 500; }; httpServer_->feedResponse(httpCode, A2STR::NIL, - responseData, + std::move(responseData), getJsonRpcContentType(!callback.empty())); } addHttpServerResponseCommand(); @@ -135,7 +135,7 @@ void HttpServerBodyCommand::sendJsonRpcBatchResponse { bool gzip = httpServer_->supportsGZip(); std::string responseData = rpc::toJsonBatch(results, callback, gzip); - httpServer_->feedResponse(responseData, + httpServer_->feedResponse(std::move(responseData), getJsonRpcContentType(!callback.empty())); addHttpServerResponseCommand(); } @@ -233,7 +233,7 @@ bool HttpServerBodyCommand::execute() rpc::RpcResponse res = method->execute(req, e_); bool gzip = httpServer_->supportsGZip(); std::string responseData = rpc::toXml(res, gzip); - httpServer_->feedResponse(responseData, "text/xml"); + httpServer_->feedResponse(std::move(responseData), "text/xml"); addHttpServerResponseCommand(); #else // !ENABLE_XML_RPC httpServer_->feedResponse(404);