Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/buffer/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -137,4 +137,4 @@ void Buffer::MakeSpace_(size_t len) {
writePos_ = readPos_ + readable;
assert(readable == ReadableBytes());
}
}
}
7 changes: 5 additions & 2 deletions code/http/httprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -264,4 +267,4 @@ std::string HttpRequest::GetPost(const char* key) const {
return post_.find(key)->second;
}
return "";
}
}
4 changes: 2 additions & 2 deletions code/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockDeque<std::string>> newDeque(new BlockDeque<std::string>);
unique_ptr<BlockDeque<std::string>> newDeque(new BlockDeque<std::string>(maxQueueSize));
deque_ = move(newDeque);

std::unique_ptr<std::thread> NewThread(new thread(FlushLogThread));
Expand Down Expand Up @@ -190,4 +190,4 @@ Log* Log::Instance() {

void Log::FlushLogThread() {
Log::Instance()->AsyncWrite_();
}
}
10 changes: 4 additions & 6 deletions code/timer/heaptimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -129,4 +127,4 @@ int HeapTimer::GetNextTick() {
if(res < 0) { res = 0; }
}
return res;
}
}