Skip to content

Commit

Permalink
🎨 adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
markparticle committed Sep 23, 2020
1 parent b2ac521 commit 2a38e2c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
10 changes: 3 additions & 7 deletions code/http/httpconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ void HttpConn::init(int fd, const sockaddr_in& addr) {
userCount++;
addr_ = addr;
fd_ = fd;
reset();
LOG_INFO("Client[%d](%s:%d) in, userCount:%d", fd_, GetIP(), GetPort(), (int)userCount);
}

void HttpConn::reset() {
writeBuff_.RetrieveAll();
readBuff_.RetrieveAll();
isClose_ = false;
LOG_INFO("Client[%d](%s:%d) in, userCount:%d", fd_, GetIP(), GetPort(), (int)userCount);
}

void HttpConn::Close() {
Expand Down Expand Up @@ -116,12 +112,12 @@ bool HttpConn::process() {
iov_[0].iov_len = writeBuff_.ReadableBytes();
iovCnt_ = 1;

/* 响应文件 */
/* 文件 */
if(response_.FileLen() > 0 && response_.File()) {
iov_[1].iov_base = response_.File();
iov_[1].iov_len = response_.FileLen();
iovCnt_ = 2;
}
}
LOG_DEBUG("filesize:%d, %d to %d", response_.FileLen() , iovCnt_, ToWriteBytes());
return true;
}
9 changes: 8 additions & 1 deletion code/http/httpconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,31 @@
class HttpConn {
public:
HttpConn();

~HttpConn();

void init(int sockFd, const sockaddr_in& addr);
void reset();

ssize_t read(int* saveErrno);

ssize_t write(int* saveErrno);

void Close();

int GetFd() const;

int GetPort() const;

const char* GetIP() const;

sockaddr_in GetAddr() const;

bool process();

int ToWriteBytes() {
return iov_[0].iov_len + iov_[1].iov_len;
}

bool IsKeepAlive() const {
return request_.IsKeepAlive();
}
Expand Down
2 changes: 1 addition & 1 deletion code/http/httpresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void HttpResponse::AddHeader_(Buffer& buff) {
buff.Append("Connection: ");
if(isKeepAlive_) {
buff.Append("keep-alive\r\n");
buff.Append("keep-alive: max=5, timeout=120\r\n");
buff.Append("keep-alive: max=6, timeout=120\r\n");
} else{
buff.Append("close\r\n");
}
Expand Down
2 changes: 1 addition & 1 deletion code/log/blockqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BlockDeque {
template<class T>
BlockDeque<T>::BlockDeque(size_t MaxCapacity) :capacity_(MaxCapacity) {
assert(MaxCapacity > 0);
isClose_ = false;
isClose_ = false;
}

template<class T>
Expand Down
5 changes: 3 additions & 2 deletions code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
int main() {
/* 守护进程 后台运行 */
//daemon(1, 0);

WebServer server(
1316, 3, 60000, false, /* 端口 ET模式 timeoutMs 优雅退出 */
1316, 3, 60000, false, /* 端口 ET模式 timeoutMs 优雅退出 */
3306, "root", "root", "webserver", /* Mysql配置 */
12, 6, true, 1, 1024); /* 连接池数量 线程池数量 日志开关 日志等级 日志异步队列容量 */
12, 6, true, 1, 1024); /* 连接池数量 线程池数量 日志开关 日志等级 日志异步队列容量 */
server.Start();
}

2 changes: 1 addition & 1 deletion code/server/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void WebServer::DealListen_() {
socklen_t len = sizeof(addr);
do {
int fd = accept(listenFd_, (struct sockaddr *)&addr, &len);
if(fd <= 0) { break;}
if(fd <= 0) { return;}
else if(HttpConn::userCount >= MAX_FD) {
SendError_(fd, "Server busy!");
LOG_WARN("Clients is full!");
Expand Down

0 comments on commit 2a38e2c

Please sign in to comment.