-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
67 lines (57 loc) · 1.41 KB
/
main.c
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
67
/* geekhttpd main file
*
* date: 2010/4/15
* author: Chengdong.Lee
* mail: [email protected]
*
*/
#include "./config/config.h"
#include "./daemon/daemon.h"
#include "./net/socket.h"
#include "./thread/task.h"
/*---------------------- main ----------------------------------*/
int main(int argc, char ** argv)
{
int listenfd; // 监听文件描述符
int res; // 保存函数的返回值
/* 先载入默认配置,如果用户有更改就使用更改的配置*/
res = geekhttpd_default_cfg();
if (-1 == res)
return -1;
if (!(access(GEEKHTTPD_DEFAULT_CONFIG_PATH, R_OK))) {
res = geekhttpd_read_config(GEEKHTTPD_DEFAULT_CONFIG_PATH);
if (-1 == res)
return -1;
}
geekhttpd_cfginfo_print();
/* daemon 模块*/
res = geekhttpd_daemon();
if ( -1 == res )
goto cfg_cleanup;
/* 创建socket 并在指定的端口上进行监听*/
res = geekhttpd_bind();
if ( -1 == res )
goto log_close;
res = geekhttpd_epoll_create();
if ( -1 == res )
goto socket_cleanup;
/* 创建线程池 */
res = geekhttpd_create_thread_pool();
if ( -1 == res ) {
syslog(LOG_INFO, "Cannot create thread pool");
goto socket_cleanup;
}
/* 启动监听并处理 */
syslog(LOG_INFO, "geekhttp started..");
res = geekhttpd_epoll_wait();
if ( -1 == res )
goto socket_cleanup;
/* SHOULD never come to here! */
socket_cleanup:
/* TODO */
cfg_cleanup:
geekhttpd_cfg_free();
log_close:
closelog();
return res;
}