閱讀nginx源碼_win32

來源:互聯網
上載者:User
本打算周末好好看看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();// 初始化Regex庫#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教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.