Skip to content

Commit

Permalink
fix Stick package
Browse files Browse the repository at this point in the history
  • Loading branch information
linyacool committed Feb 14, 2018
1 parent a13bc57 commit d14b713
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion WebBench/test.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./bin/webbench -t 60 -c 1000 -2 --get http://127.0.0.1:8888/hello
./bin/webbench -t 60 -c 1000 -2 --get http://127.0.0.1:80/hello
11 changes: 5 additions & 6 deletions WebServer/HttpData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ HttpData::HttpData(EventLoop *loop, int connfd):

void HttpData::reset()
{
inBuffer_.clear();
//inBuffer_.clear();
fileName_.clear();
path_.clear();
nowReadPos_ = 0;
Expand Down Expand Up @@ -222,13 +222,11 @@ void HttpData::handleRead()
if (!error_ && state_ == STATE_FINISH)
{

if (keepAlive_ && connectionState_ == H_CONNECTED)
if ((keepAlive_ || inBuffer_.size() > 0) && connectionState_ == H_CONNECTED)
{
this->reset();
events_ |= EPOLLIN;
}
else
return;
}
else if (!error_ && connectionState_ != H_DISCONNECTED)
events_ |= EPOLLIN;
Expand Down Expand Up @@ -398,7 +396,8 @@ HeaderState HttpData::parseHeaders()
int key_start = -1, key_end = -1, value_start = -1, value_end = -1;
int now_read_line_begin = 0;
bool notFinish = true;
for (size_t i = 0; i < str.size() && notFinish; ++i)
size_t i = 0;
for (; i < str.size() && notFinish; ++i)
{
switch(hState_)
{
Expand Down Expand Up @@ -501,7 +500,7 @@ HeaderState HttpData::parseHeaders()
}
if (hState_ == H_END_LF)
{
str = str.substr(now_read_line_begin);
str = str.substr(i);
return PARSE_HEADER_SUCCESS;
}
str = str.substr(now_read_line_begin);
Expand Down
4 changes: 2 additions & 2 deletions 连接的维护.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

* 对于server端,毫无疑问应该谨慎处理以上所有情况。具体说来:
> * 出现各种关于连接的错误时,可以直接close()掉
> * 短连接超时的请求,可以直接close()
> * 长连接对方长时间没有请求(如果没有保活机制),可以close()
> * 短连接超时的请求,可以close(),也可以不关
> * 长连接对方长时间没有请求(如果没有保活机制),可以close(),也可以不关
> * client发出Fin,server应当把消息发完,然后才可以close()
> * 短连接正常结束,server可以close,也可以不close,大多数的实现是不close的(对HTTP1.1而言)
Expand Down

0 comments on commit d14b713

Please sign in to comment.