本打算周末好好看看nginx源码的,却玩了两天的游戏。
还没有开始编译nginx,cygwin还没装好,mirror不给力啊。过了一遍http://blog.csdn.net/kenbinzhang/article/category/603177关于nginx系列的文章,对nginx工程结构有了个大致的印象。
int ngx_cdecl main(int argc, char *const *argv)
{
ngx_int_t i;
ngx_log_t *log;
ngx_cycle_t *cycle, init_cycle;
ngx_core_conf_t *ccf;
ngx_debug_init();
ngx_strerror_init();
ngx_get_options(argc, argv); // 解析程序参数,设置对应的全局变量
if (ngx_show_version) {
// 输出nginx版本
if (ngx_show_help) {
// 输出程序帮助
}
if (ngx_show_configure) {
// 输出nginx编译配置
}
if (!ngx_test_config) {
return 0;
}
}
/* 计算了一下每种日期格式的字符串长度,并调用ngx_time_update。
每调用一次ngx_time_update,会更新一个日期字符串cache对应slot里面的日期字符
更新顺序为0~63 0~63 …… Question:它这个Cache有什么用?*/
ngx_time_init(); // TODO
#if (NGX_PCRE)
ngx_regex_init(); // 初始化正则表达式库
#endif
ngx_pid = ngx_getpid();
/*初始化日志文件。ngx_prefix是在ngx_get_options函数中解析出来的,
如果没有制定-p参数,那么它就是NULL,此时,程序采用NGX_PREFIX作为日志存储目录。
*/
log = ngx_log_init(ngx_prefix);
/* STUB */
#if (NGX_OPENSSL)
ngx_ssl_init(log);
#endif
ngx_memzero(&init_cycle, sizeof(ngx_cycle_t));
init_cycle.log = log;
ngx_cycle = &init_cycle;
init_cycle.pool = ngx_create_pool(1024, log);
/*argc存到了ngx_argc变量中,argv存到了ngx_os_argv变量中、每个命令行参数
存到了ngx_argv变量中,ngx_os_environ记录了程序环境变量。*/
ngx_save_argv(&init_cycle, argc, argv);
/*初始化了init_cycle中关于conf文件的一些配置*/
ngx_process_options(&init_cycle);
/*获取操作系统信息。这个链接到的是ngx_win32_init.c中的函数。
这个函数里面调用了WSAStartup来初始化winsock。同时,这个函数里面还通过
WSAIoctl的SIO_GET_EXTENSION_FUNCTION_POINTER选项获取socket的扩展API*/
ngx_os_init(log);
ngx_crc32_table_init();
// Question: 没看明白
ngx_add_inherited_sockets(&init_cycle);
ngx_max_module = 0;
// 网上说ngx_modules变量是在运行auto/configure脚本的时候生成的
for (i = 0; ngx_modules[i]; i++) {
ngx_modules[i]->index = ngx_max_module++;
}
/* 这个函数有点长,粗略看了一下,包含初始化init_cycle中一些重要的成员
配置解析、配置文件解析等*/
cycle = ngx_init_cycle(&init_cycle);
if (ngx_test_config) {
return 0;
}
if (ngx_signal) {
return ngx_signal_process(cycle, ngx_signal);
}
ngx_os_status(cycle->log);
ngx_cycle = cycle;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (ccf->master && ngx_process == NGX_PROCESS_SINGLE) {
ngx_process = NGX_PROCESS_MASTER;
}
ngx_create_pidfile(&ccf->pid, cycle->log);
ngx_log_redirect_stderr(cycle);
if (log->file->fd != ngx_stderr) {
if (ngx_close_file(log->file->fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_close_file_n " built-in log failed");
}
}
ngx_use_stderr = 0;
if (ngx_process == NGX_PROCESS_SINGLE) {
ngx_single_process_cycle(cycle);
} else {
ngx_master_process_cycle(cycle);
}
return 0;
}
以上就介绍了阅读nginx源码_win32,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号