代码拉取完成,页面将自动刷新
// 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。