-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# 核心结构体 | ||
|
||
1. 配置信息结构(unil.h) | ||
```C++ | ||
typedef struct tk_conf{ | ||
char root[PATHLEN]; // 文件根目录 | ||
int port; // 端口号 | ||
int thread_num; // 线程数(线程池大小) | ||
}tk_conf_t; | ||
``` | ||
|
||
2. 请求信息结构(http_request.h) | ||
```C++ | ||
typedef struct tk_http_request{ | ||
char* root; // 配置目录 | ||
int fd; // 描述符(监听、连接) | ||
int epoll_fd; // epoll描述符 | ||
char buff[MAX_BUF]; // 用户缓冲 | ||
int method; // 请求方法 | ||
int state; // 请求头解析状态 | ||
// 以下主要为标记解析请求时索引信息 | ||
// 部分未使用,用于扩展功能 | ||
size_t pos; | ||
size_t last; | ||
void *request_start; | ||
void *method_end; | ||
void *uri_start; | ||
void *uri_end; | ||
void *path_start; | ||
void *path_end; | ||
void *query_start; | ||
void *query_end; | ||
int http_major; | ||
int http_minor; | ||
void *request_end; | ||
struct list_head list; | ||
void *cur_header_key_start; | ||
void *cur_header_key_end; | ||
void *cur_header_value_start; | ||
void *cur_header_value_end; | ||
void *timer; // 指向时间戳结构 | ||
}tk_http_request_t; | ||
``` | ||
|
||
3. 响应头结构(http_requesh.h) | ||
```C++ | ||
typedef struct tk_http_out{ | ||
int fd; // 连接描述符 | ||
int keep_alive; // HTTP连接状态 | ||
time_t mtime; // 文件类型 | ||
int modified; // 是否修改 | ||
int status; // 返回码 | ||
}tk_http_out_t; | ||
``` | ||
|
||
4. 优先队列结构(priority_queue.h) | ||
```C++ | ||
typedef struct priority_queue{ | ||
void **pq; // 优先队列节点指针 | ||
size_t nalloc; // 优先队列实际元素个数 | ||
size_t size; // 优先队列大小 | ||
tk_pq_comparator_pt comp; // 堆模式 | ||
}tk_pq_t; | ||
``` | ||
|
||
5. 时间结构(timer.h) | ||
```C++ | ||
typedef struct tk_timer{ | ||
size_t key; // 标记超时时间 | ||
int deleted; // 标记是否被删除 | ||
timer_handler_pt handler; // 超时处理 | ||
tk_http_request_t *request; // 指向对应的request请求 | ||
} tk_timer_t; | ||
``` | ||
|
||
6. I/O包结构(rio.h) | ||
```C++ | ||
typedef struct{ | ||
int rio_fd; // 描述符 | ||
ssize_t rio_cnt; // buf中未读字节数 | ||
char *rio_bufptr; // 下一个未读字符指针 | ||
char rio_buf[RIO_BUFSIZE]; // 缓冲 | ||
}rio_t; | ||
``` | ||
|
||
7. 线程池结构(threadpool.h) | ||
```C++ | ||
typedef struct threadpool{ | ||
pthread_mutex_t lock; // 互斥锁 | ||
pthread_cond_t cond; // 条件变量 | ||
pthread_t *threads; // 线程 | ||
tk_task_t *head; // 任务链表 | ||
int thread_count; // 线程数 | ||
int queue_size; // 任务链表长 | ||
int shutdown; // 关机方式 | ||
int started; | ||
}tk_threadpool_t; | ||
``` | ||
|
||
8. 任务结构(threadpool.h) | ||
```C++ | ||
typedef struct tk_task{ | ||
void (*func)(void *); // | ||
void *arg; // | ||
struct tk_task *next; // 任务链表(下一节点指针) | ||
}tk_task_t; | ||
``` | ||
--- |