Mercurial > hg > nginx-vendor-0-8
diff src/http/modules/perl/nginx.xs @ 332:3a91bfeffaba NGINX_0_6_10
nginx 0.6.10
*) Feature: the "open_file_cache", "open_file_cache_retest", and
"open_file_cache_errors" directives.
*) Bugfix: socket leak; bug appeared in 0.6.7.
*) Bugfix: a charset set by the "charset" directive was not appended to
the "Content-Type" header set by $r->send_http_header().
*) Bugfix: a segmentation fault might occur in worker process if
/dev/poll method was used.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 03 Sep 2007 00:00:00 +0400 |
parents | 9fc4ab6673f9 |
children | 10cc350ed8a1 |
line wrap: on
line diff
--- a/src/http/modules/perl/nginx.xs +++ b/src/http/modules/perl/nginx.xs @@ -131,6 +131,8 @@ send_http_header(r, ...) XSRETURN_EMPTY; } + r->headers_out.content_type_len = r->headers_out.content_type.len; + } else { if (ngx_http_set_content_type(r) != NGX_OK) { XSRETURN_EMPTY; @@ -603,15 +605,15 @@ void sendfile(r, filename, offset = -1, bytes = 0) CODE: - ngx_http_request_t *r; - char *filename; - int offset; - size_t bytes; - ngx_fd_t fd; - ngx_buf_t *b; - ngx_file_info_t fi; - ngx_pool_cleanup_t *cln; - ngx_pool_cleanup_file_t *clnf; + ngx_http_request_t *r; + char *filename; + int offset; + size_t bytes; + ngx_int_t rc; + ngx_str_t path; + ngx_buf_t *b; + ngx_open_file_info_t of; + ngx_http_core_loc_conf_t *clcf; ngx_http_perl_set_request(r); @@ -634,14 +636,30 @@ sendfile(r, filename, offset = -1, bytes XSRETURN_EMPTY; } - cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t)); - if (cln == NULL) { + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + of.test_dir = 0; + of.retest = clcf->open_file_cache_retest; + of.errors = clcf->open_file_cache_errors; + of.events = clcf->open_file_cache_events; + + path.len = ngx_strlen(filename); + + path.data = ngx_pcalloc(r->pool, path.len + 1); + if (path.data == NULL) { XSRETURN_EMPTY; } - fd = ngx_open_file((u_char *) filename, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); + (void) ngx_cpystrn(path.data, filename, path.len + 1); + + rc = ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool); - if (fd == NGX_INVALID_FILE) { + if (rc == NGX_ERROR) { + + if (of.err == 0) { + XSRETURN_EMPTY; + } + ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, ngx_open_file_n " \"%s\" failed", filename); XSRETURN_EMPTY; @@ -652,34 +670,15 @@ sendfile(r, filename, offset = -1, bytes } if (bytes == 0) { - if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, - ngx_fd_info_n " \"%s\" failed", filename); - - if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, - ngx_close_file_n " \"%s\" failed", filename); - } - - XSRETURN_EMPTY; - } - - bytes = ngx_file_size(&fi) - offset; + bytes = of.size - offset; } - cln->handler = ngx_pool_cleanup_file; - clnf = cln->data; - - clnf->fd = fd; - clnf->name = (u_char *) ""; - clnf->log = r->pool->log; - b->in_file = 1; b->file_pos = offset; b->file_last = offset + bytes; - b->file->fd = fd; + b->file->fd = of.fd; b->file->log = r->connection->log; (void) ngx_http_perl_output(r, b);