Check !SocketRecvBuffer::bufferEmpty() in ctor.

Also treat !SocketRecvBuffer::bufferEmpty() as data is available.
pull/1/head
Tatsuhiro Tsujikawa 2011-01-16 17:52:18 +09:00
parent e60181d1ad
commit b2f27e6548
4 changed files with 28 additions and 2 deletions

View File

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

View File

@ -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()) {

View File

@ -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;

View File

@ -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);