Browse Source

Use move to send string data into SocketBuffer::pushStr

Tatsuhiro Tsujikawa 12 years ago
parent
commit
fba7e7ee8b
5 changed files with 37 additions and 36 deletions
  1. 13 13
      src/FtpConnection.cc
  2. 2 2
      src/HttpConnection.cc
  3. 16 15
      src/HttpServer.cc
  4. 2 2
      src/HttpServer.h
  5. 4 4
      src/HttpServerBodyCommand.cc

+ 13 - 13
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<SocketCore>& 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<SocketCore>& 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)
           segment->getPositionToWrite() : static_cast<int64_t>(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();

+ 2 - 2
src/HttpConnection.cc

@@ -105,7 +105,7 @@ void HttpConnection::sendRequest(const std::shared_ptr<HttpRequest>& 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<HttpRequestEntry> 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<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
   outstandingHttpRequests_.push_back(entry);

+ 16 - 15
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<unsigned long>(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<unsigned long>(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()

+ 2 - 2
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

+ 4 - 4
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);