Переглянути джерело

Check !SocketRecvBuffer::bufferEmpty() in ctor.

Also treat !SocketRecvBuffer::bufferEmpty() as data is available.
Tatsuhiro Tsujikawa 14 роки тому
батько
коміт
b2f27e6548
4 змінених файлів з 28 додано та 2 видалено
  1. 5 0
      src/HttpServer.h
  2. 8 1
      src/HttpServerBodyCommand.cc
  3. 13 1
      src/HttpServerCommand.cc
  4. 2 0
      src/HttpServerCommand.h

+ 5 - 0
src/HttpServer.h

@@ -116,6 +116,11 @@ public:
   void disableGZip() { gzip_ = false; }
 
   uint64_t getContentLength() const { return lastContentLength_; }
+
+  const SharedHandle<SocketRecvBuffer>& getSocketRecvBuffer() const
+  {
+    return socketRecvBuffer_;
+  }
 };
 
 } // namespace aria2

+ 8 - 1
src/HttpServerBodyCommand.cc

@@ -53,6 +53,7 @@
 #include "wallclock.h"
 #include "util.h"
 #include "fmt.h"
+#include "SocketRecvBuffer.h"
 
 namespace aria2 {
 
@@ -66,8 +67,12 @@ HttpServerBodyCommand::HttpServerBodyCommand
     socket_(socket),
     httpServer_(httpServer)
 {
+  // To handle Content-Length == 0 case
   setStatus(Command::STATUS_ONESHOT_REALTIME);
   e_->addSocketForReadCheck(socket_, this);
+  if(!httpServer_->getSocketRecvBuffer()->bufferEmpty()) {
+    e_->setNoWait(true);
+  }
 }
 
 HttpServerBodyCommand::~HttpServerBodyCommand()
@@ -81,7 +86,9 @@ bool HttpServerBodyCommand::execute()
     return true;
   }
   try {
-    if(socket_->isReadable(0) || httpServer_->getContentLength() == 0) {
+    if(socket_->isReadable(0) ||
+       !httpServer_->getSocketRecvBuffer()->bufferEmpty() ||
+       httpServer_->getContentLength() == 0) {
       timeoutTimer_ = global::wallclock;
 
       if(httpServer_->receiveBody()) {

+ 13 - 1
src/HttpServerCommand.cc

@@ -49,6 +49,7 @@
 #include "util.h"
 #include "wallclock.h"
 #include "fmt.h"
+#include "SocketRecvBuffer.h"
 
 namespace aria2 {
 
@@ -70,6 +71,7 @@ HttpServerCommand::HttpServerCommand
 #else // !HAVE_LIBZ
   httpServer_->disableGZip();
 #endif // !HAVE_LIBZ
+  checkSocketRecvBuffer();
 }
 
 HttpServerCommand::HttpServerCommand
@@ -83,6 +85,7 @@ HttpServerCommand::HttpServerCommand
     httpServer_(httpServer)
 {
   e_->addSocketForReadCheck(socket_, this);
+  checkSocketRecvBuffer();
 }
 
 HttpServerCommand::~HttpServerCommand()
@@ -90,13 +93,22 @@ HttpServerCommand::~HttpServerCommand()
   e_->deleteSocketForReadCheck(socket_, this);
 }
 
+void HttpServerCommand::checkSocketRecvBuffer()
+{
+  if(!httpServer_->getSocketRecvBuffer()->bufferEmpty()) {
+    setStatus(Command::STATUS_ONESHOT_REALTIME);
+    e_->setNoWait(true);
+  }
+}
+
 bool HttpServerCommand::execute()
 {
   if(e_->getRequestGroupMan()->downloadFinished() || e_->isHaltRequested()) {
     return true;
   }
   try {
-    if(socket_->isReadable(0)) {
+    if(socket_->isReadable(0) ||
+       !httpServer_->getSocketRecvBuffer()->bufferEmpty()) {
       timeoutTimer_ = global::wallclock;
       SharedHandle<HttpHeader> header;
 

+ 2 - 0
src/HttpServerCommand.h

@@ -51,6 +51,8 @@ private:
   SharedHandle<SocketCore> socket_;
   SharedHandle<HttpServer> httpServer_;
   Timer timeoutTimer_;
+
+  void checkSocketRecvBuffer();
 public:
   HttpServerCommand(cuid_t cuid, DownloadEngine* e,
                     const SharedHandle<SocketCore>& socket);