diff --git a/code/buffer/buffer.cpp b/code/buffer/buffer.cpp index 1e6b77b..88cf534 100644 --- a/code/buffer/buffer.cpp +++ b/code/buffer/buffer.cpp @@ -128,7 +128,7 @@ const char* Buffer::BeginPtr_() const { void Buffer::MakeSpace_(size_t len) { if(WritableBytes() + PrependableBytes() < len) { - buffer_.resize(writePos_ + len + 1); + buffer_.resize(writePos_ + len); } else { size_t readable = ReadableBytes(); @@ -137,4 +137,4 @@ void Buffer::MakeSpace_(size_t len) { writePos_ = readPos_ + readable; assert(readable == ReadableBytes()); } -} \ No newline at end of file +} diff --git a/code/http/httprequest.cpp b/code/http/httprequest.cpp index 69bfbb1..5c5e6b0 100644 --- a/code/http/httprequest.cpp +++ b/code/http/httprequest.cpp @@ -55,7 +55,10 @@ bool HttpRequest::parse(Buffer& buff) { default: break; } - if(lineEnd == buff.BeginWrite()) { break; } + if(lineEnd == buff.BeginWrite()) { + buff.RetrieveAll(); + break; + } buff.RetrieveUntil(lineEnd + 2); } LOG_DEBUG("[%s], [%s], [%s]", method_.c_str(), path_.c_str(), version_.c_str()); @@ -264,4 +267,4 @@ std::string HttpRequest::GetPost(const char* key) const { return post_.find(key)->second; } return ""; -} \ No newline at end of file +} diff --git a/code/log/log.cpp b/code/log/log.cpp index 32ccf9b..03e1760 100644 --- a/code/log/log.cpp +++ b/code/log/log.cpp @@ -48,7 +48,7 @@ void Log::init(int level = 1, const char* path, const char* suffix, if(maxQueueSize > 0) { isAsync_ = true; if(!deque_) { - unique_ptr> newDeque(new BlockDeque); + unique_ptr> newDeque(new BlockDeque(maxQueueSize)); deque_ = move(newDeque); std::unique_ptr NewThread(new thread(FlushLogThread)); @@ -190,4 +190,4 @@ Log* Log::Instance() { void Log::FlushLogThread() { Log::Instance()->AsyncWrite_(); -} \ No newline at end of file +} diff --git a/code/timer/heaptimer.cpp b/code/timer/heaptimer.cpp index f363f6d..bc8cedc 100644 --- a/code/timer/heaptimer.cpp +++ b/code/timer/heaptimer.cpp @@ -52,11 +52,8 @@ void HeapTimer::add(int id, int timeout, const TimeoutCallBack& cb) { else { /* 已有结点:调整堆 */ i = ref_[id]; - heap_[i].expires = Clock::now() + MS(timeout); + adjust(id, timeout); heap_[i].cb = cb; - if(!siftdown_(i, heap_.size())) { - siftup_(i); - } } } @@ -93,7 +90,8 @@ void HeapTimer::adjust(int id, int timeout) { /* 调整指定id的结点 */ assert(!heap_.empty() && ref_.count(id) > 0); heap_[ref_[id]].expires = Clock::now() + MS(timeout);; - siftdown_(ref_[id], heap_.size()); + if(!siftdown_(ref_[id], heap_.size())) + siftup_(ref_[id]); } void HeapTimer::tick() { @@ -129,4 +127,4 @@ int HeapTimer::GetNextTick() { if(res < 0) { res = 0; } } return res; -} \ No newline at end of file +}