-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPconnection.h
66 lines (50 loc) · 1.45 KB
/
HTTPconnection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#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