Internals: how do I send large file to the client?

ruslan_osmanov nginx-forum at
Wed Aug 14 14:32:12 UTC 2013

I know those commands. But the question was about Nginx's internals. I
somebody would suggest a pseudo-code snippet similar to the following:

ngx_buf_t b;
size_t length = 0;

loop (files as file) {

    u_char *filename = file->name;

    if (ngx_open_cached_file(ccf->open_file_cache, filename, &of, r->pool)
            != NGX_OK)
            return NGX_ERROR;

    length += of.size;

    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
    if (b == NULL) {

    b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
    if (b->file == NULL) {

    b->file_pos = 0;
    b->file_last = of.size;
    b->in_file = b->file_last ? 1 : 0;
    b->file->fd = of.fd;
    b->file->name = *filename;
    b->file->log = r->connection->log;
    b->file->directio = of.is_directio;

    cl = ngx_alloc_chain_link(r->pool);
    if (cl == NULL) {
    cl->buf = b;

    *last_out = cl;
    last_out = &cl->next;
    cl->next = NULL;


I've found ngx_open_cached_file and ngx_alloc_chain_link just recently. I
there should be a way to chain open files without actually performing I/O
myself. Still have no clear understanding how it works and how one should
the cached files' API.

coolbhushans at Wrote:
> have u know the split command in linux . you can use that to split
> file
> then send it after you can use join command  to join files

Posted at Nginx Forum:,241796,241846#msg-241846

More information about the nginx mailing list