2 Star 30 Fork 7

Agedcat/WebServer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
HTTPconnection.h 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
i猫的少年 提交于 2021-06-03 23:31 . first finish
// encode UTF-8
// @Author : Aged_cat
// @Date : 2021-05-04
#ifndef HTTP_CONNECTION_H
#define HTTP_CONNECTION_H
#include<arpa/inet.h> //sockaddr_in
#include<sys/uio.h> //readv/writev
#include<iostream>
#include<sys/types.h>
#include<assert.h>
#include "buffer.h"
#include "HTTPrequest.h"
#include "HTTPresponse.h"
class HTTPconnection{
public:
HTTPconnection();
~HTTPconnection();
void initHTTPConn(int socketFd,const sockaddr_in& addr);
//每个连接中定义的对缓冲区的读写接口
ssize_t readBuffer(int* saveErrno);
ssize_t writeBuffer(int* saveErrno);
//关闭HTTP连接的接口
void closeHTTPConn();
//定义处理该HTTP连接的接口,主要分为request的解析和response的生成
bool handleHTTPConn();
//其他方法
const char* getIP() const;
int getPort() const;
int getFd() const;
sockaddr_in getAddr() const;
int writeBytes()
{
return iov_[1].iov_len+iov_[0].iov_len;
}
bool isKeepAlive() const
{
return request_.isKeepAlive();
}
static bool isET;
static const char* srcDir;
static std::atomic<int>userCount;
private:
int fd_; //HTTP连接对应的描述符
struct sockaddr_in addr_;
bool isClose_; //标记是否关闭连接
int iovCnt_;
struct iovec iov_[2];
Buffer readBuffer_; //读缓冲区
Buffer writeBuffer_; //写缓冲区
HTTPrequest request_;
HTTPresponse response_;
};
#endif //HTTP_CONNECTION_H
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/agedcat/WebServer.git
git@gitee.com:agedcat/WebServer.git
agedcat
WebServer
WebServer
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385