comparison 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
comparison
equal deleted inserted replaced
331:b69d5e83bf82 332:3a91bfeffaba
128 if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv) 128 if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv)
129 != NGX_OK) 129 != NGX_OK)
130 { 130 {
131 XSRETURN_EMPTY; 131 XSRETURN_EMPTY;
132 } 132 }
133
134 r->headers_out.content_type_len = r->headers_out.content_type.len;
133 135
134 } else { 136 } else {
135 if (ngx_http_set_content_type(r) != NGX_OK) { 137 if (ngx_http_set_content_type(r) != NGX_OK) {
136 XSRETURN_EMPTY; 138 XSRETURN_EMPTY;
137 } 139 }
601 603
602 void 604 void
603 sendfile(r, filename, offset = -1, bytes = 0) 605 sendfile(r, filename, offset = -1, bytes = 0)
604 CODE: 606 CODE:
605 607
606 ngx_http_request_t *r; 608 ngx_http_request_t *r;
607 char *filename; 609 char *filename;
608 int offset; 610 int offset;
609 size_t bytes; 611 size_t bytes;
610 ngx_fd_t fd; 612 ngx_int_t rc;
611 ngx_buf_t *b; 613 ngx_str_t path;
612 ngx_file_info_t fi; 614 ngx_buf_t *b;
613 ngx_pool_cleanup_t *cln; 615 ngx_open_file_info_t of;
614 ngx_pool_cleanup_file_t *clnf; 616 ngx_http_core_loc_conf_t *clcf;
615 617
616 ngx_http_perl_set_request(r); 618 ngx_http_perl_set_request(r);
617 619
618 filename = SvPV_nolen(ST(1)); 620 filename = SvPV_nolen(ST(1));
619 621
632 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); 634 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
633 if (b->file == NULL) { 635 if (b->file == NULL) {
634 XSRETURN_EMPTY; 636 XSRETURN_EMPTY;
635 } 637 }
636 638
637 cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t)); 639 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
638 if (cln == NULL) { 640
639 XSRETURN_EMPTY; 641 of.test_dir = 0;
640 } 642 of.retest = clcf->open_file_cache_retest;
641 643 of.errors = clcf->open_file_cache_errors;
642 fd = ngx_open_file((u_char *) filename, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); 644 of.events = clcf->open_file_cache_events;
643 645
644 if (fd == NGX_INVALID_FILE) { 646 path.len = ngx_strlen(filename);
647
648 path.data = ngx_pcalloc(r->pool, path.len + 1);
649 if (path.data == NULL) {
650 XSRETURN_EMPTY;
651 }
652
653 (void) ngx_cpystrn(path.data, filename, path.len + 1);
654
655 rc = ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool);
656
657 if (rc == NGX_ERROR) {
658
659 if (of.err == 0) {
660 XSRETURN_EMPTY;
661 }
662
645 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, 663 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
646 ngx_open_file_n " \"%s\" failed", filename); 664 ngx_open_file_n " \"%s\" failed", filename);
647 XSRETURN_EMPTY; 665 XSRETURN_EMPTY;
648 } 666 }
649 667
650 if (offset == -1) { 668 if (offset == -1) {
651 offset = 0; 669 offset = 0;
652 } 670 }
653 671
654 if (bytes == 0) { 672 if (bytes == 0) {
655 if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { 673 bytes = of.size - offset;
656 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, 674 }
657 ngx_fd_info_n " \"%s\" failed", filename);
658
659 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
660 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
661 ngx_close_file_n " \"%s\" failed", filename);
662 }
663
664 XSRETURN_EMPTY;
665 }
666
667 bytes = ngx_file_size(&fi) - offset;
668 }
669
670 cln->handler = ngx_pool_cleanup_file;
671 clnf = cln->data;
672
673 clnf->fd = fd;
674 clnf->name = (u_char *) "";
675 clnf->log = r->pool->log;
676 675
677 b->in_file = 1; 676 b->in_file = 1;
678 677
679 b->file_pos = offset; 678 b->file_pos = offset;
680 b->file_last = offset + bytes; 679 b->file_last = offset + bytes;
681 680
682 b->file->fd = fd; 681 b->file->fd = of.fd;
683 b->file->log = r->connection->log; 682 b->file->log = r->connection->log;
684 683
685 (void) ngx_http_perl_output(r, b); 684 (void) ngx_http_perl_output(r, b);
686 685
687 686