diff --git a/event/connection.c b/event/connection.c index cb2937a..f488bce 100644 --- a/event/connection.c +++ b/event/connection.c @@ -41,7 +41,6 @@ int conn_pool_init(mem_pool *p, int size) return FCY_OK; } -/* 从空闲链表中取出一个连接 */ connection *conn_get() { list_node *head; diff --git a/event/connection.h b/event/connection.h index c3af9f0..6254f78 100644 --- a/event/connection.h +++ b/event/connection.h @@ -1,5 +1,7 @@ // // Created by frank on 17-2-12. +// TCP connection pool +// the size of pool is determined by worker connection configuration // #ifndef FANCY_CONN_POOL_H @@ -12,26 +14,27 @@ typedef struct connection connection; typedef struct connection peer_connection; -/* call conn_get to get a connection */ struct connection { int sockfd; event read; event write; - peer_connection *peer; // 上游/下游连接 + peer_connection *peer; // user or upstream connection void *app; // request, upstream int app_count; - struct sockaddr_in addr; + struct sockaddr_in addr; // peer address list_node node; }; int conn_pool_init(mem_pool *p, int size); +/* conn_get is the only way to get a connection */ connection *conn_get(); + void conn_free(connection *conn); char *conn_str(connection *conn); diff --git a/event/event.c b/event/event.c index 2ce4f61..6923ce7 100644 --- a/event/event.c +++ b/event/event.c @@ -51,7 +51,7 @@ int event_process(timer_msec timeout) return FCY_ERROR; } else if (n_ev == 0) { - /* 超时 */ + /* timeout */ return 0; } @@ -60,7 +60,7 @@ int event_process(timer_msec timeout) events = e_event->events; conn = e_event->data.ptr; - /* 检测到错误或者对端关闭连接,交给read_handler或者write_handler解决 */ + /* error detected, throw it to read_handler or write_handler */ if (events & (EPOLLERR | EPOLLRDHUP)) { events |= EPOLLIN | EPOLLOUT ; } @@ -72,7 +72,7 @@ int event_process(timer_msec timeout) wevent = &conn->write; if (wevent->active && (events & EPOLLOUT)) { - // 忽略过期事件 + // ignore timeout event if (conn->sockfd == -1) { continue; } diff --git a/event/event.h b/event/event.h index 04ac22d..057791c 100644 --- a/event/event.h +++ b/event/event.h @@ -17,9 +17,9 @@ typedef void (*event_handler)(event *); struct event { - unsigned active:1; // 是否在epoll_wait中 - unsigned timer_set:1; // 是否在定时器中 - unsigned timeout:1; // 是否为超时事件 + unsigned active:1; // is in epoll_wait ? + unsigned timer_set:1; // is in timer ? + unsigned timeout:1; // is timeout ? rbtree_node rb_node; diff --git a/event/timer.c b/event/timer.c index 5951006..3047669 100644 --- a/event/timer.c +++ b/event/timer.c @@ -84,18 +84,19 @@ static timer_msec timer_recent() rbtree_node *recent; timer_msec current; - /* 计时器为空, 表示不会有任何事件发生 */ + /* no event is waiting */ if (rbtree_empty(&timer)) { return TIMER_INFINITE; } recent = rbtree_min(&timer); current = current_msec(); - if (current < recent->key) { /* 没有事件发生,返回最近事件的时间差值 */ + if (current < recent->key) { + /* event will be timeout in the future */ return recent->key - current; } - /* 有事件发生 */ + /* event already timeout */ return 0; } diff --git a/http/http.c b/http/http.c index 9686357..a3d59a3 100644 --- a/http/http.c +++ b/http/http.c @@ -11,14 +11,14 @@ #include "request.h" #include "upstream.h" -/* 通用的handler */ +/* generic handler */ static void accept_h(event *); static void read_request_headers_h(event *); static void parse_request_h(event *); static void read_request_body(event *); static void process_request_h(event *); -/* 专门处理动态内容的 handler */ +/* dynamic content handler */ static void peer_connect_h(event *); static void upstream_write_request_h(event *); static void upstream_read_response_header_h(event *); @@ -29,7 +29,7 @@ static void write_response_all_h(event *); static void write_response_headers_h(event *); static void send_file_h(event *); -/* 表示一个请求处理完成,可能关闭连接,也可能keep_alive */ +/* a request is finished, connection can be closed or keep alive */ static void finalize_request_h(event *); static void response_and_close(connection *conn, int status_code);