File io 如何正确使用ngx_write_chain_到_temp_文件?

File io 如何正确使用ngx_write_chain_到_temp_文件?,file-io,nginx,File Io,Nginx,我正在编写nginx模块,该模块构造nginx链,然后将该链缓冲区写入nginx临时文件,以便稍后使用(就在写入发生之后)。我一直在搜索每一页,唯一的解决方案是下面的一个: // Create temp file to test ngx_temp_file_t *tf; tf = ngx_pcalloc(r->pool, sizeof (ngx_temp_file_t)); if (tf == NULL) {

我正在编写nginx模块,该模块构造nginx链,然后将该链缓冲区写入nginx临时文件,以便稍后使用(就在写入发生之后)。我一直在搜索每一页,唯一的解决方案是下面的一个:

// Create temp file to test
            ngx_temp_file_t *tf;
            tf = ngx_pcalloc(r->pool, sizeof (ngx_temp_file_t));
            if (tf == NULL) {
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
            }
            tf->file.fd = NGX_INVALID_FILE;
            tf->file.log = nlog;
            tf->path = clcf->client_body_temp_path;
            tf->pool = r->pool;
            tf->log_level = r->request_body_file_log_level;
            tf->persistent = r->request_body_in_persistent_file;
            tf->clean = r->request_body_in_clean_file;
            //        if (r->request_body_file_group_access) {
            //            tf->access = 0660;
            //        }
            if (ngx_create_temp_file(&tf->file, tf->path, tf->pool, tf->persistent, tf->clean, tf->access) != NGX_OK) {
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
            }

            if (ngx_write_chain_to_temp_file(tf, bucket->first) == NGX_ERROR) {
                return NGX_HTTP_INTERNAL_SERVER_ERROR;
            }
此代码不返回NGX_错误,这是否意味着nginx成功地将临时文件写入客户端_body_temporay_路径?答案是肯定的,之后,我用fopen打开文件,文件不存在吗


有人能给我一个正确的解决方案来处理ngx文件吗?

我找到了解决方案

        ngx_temp_file_t *tf;
        tf = ngx_pcalloc(r->pool, sizeof (ngx_temp_file_t));
        tf->file.fd = NGX_INVALID_FILE;
        tf->file.log = nlog;
        tf->path = clcf->client_body_temp_path;
        tf->pool = r->pool;
        tf->persistent = 1;
        rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, tf->persistent, tf->clean, tf->access);
        //ngx_write_chain_to_file(&tf->file, bucket->first, bucket->content_length, r->pool);
        ngx_write_chain_to_temp_file(tf, bucket->first);
我唯一不能理解的是,如果我将
tf->persistent
设置为false(0),那么在创建文件之后,即使我还没有将响应传递给output\u filter,我也无法从中读取