Welcome! Log In Create A New Profile

Advanced

Re: custom handler module - dynamic response with unknown content length

Maxim Dounin
February 28, 2014 07:12PM
Hello!

On Fri, Feb 28, 2014 at 10:44:38PM +0330, Yasser Zamani wrote:

> Hi there,
>
> I learned some about how to write a handler module from [1] and [2].
> [1] http://blog.zhuzhaoyuan.com/2009/08/creating-a-hello-world-nginx-module/
> [2] http://www.evanmiller.org/nginx-modules-guide.html#compiling
>
> But I need to rewrite [1] to send dynamically generated octect stream to
> client with unknown content length but it'll be large usually. Firstly I
> tried:

[...]

> /* send the buffer chain of your response */
> int i;
> for(i=1;i<10000000;i++){b->flush =
> (0==(i%1000));rc=ngx_http_output_filter(r,
> &out);if(rc!=NGX_OK){ngx_log_error(NGX_LOG_ALERT,r->connection->log,0,"bad
> rc, rc:%d", rc);return rc;}}
> b->last_buf = 1;
> return ngx_http_output_filter(r, &out);
>
> But it simply fails with following errors:
>
> 2014/02/28 22:17:25 [alert] 25115#0: *1 zero size buf in writer t:0 r:0 f:0
> 00000000 080C7431-080C7431 00000000 0-0, client: 127.0.0.1, server:
> localhost, request: "GET / HTTP/1.1", host: "localhost:8080"
> 2014/02/28 22:17:25 [alert] 25115#0: *1 bad rc, rc:-1, client: 127.0.0.1,
> server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"

You've tried to send the same chain with the same buffer multiple
times. After a buffer is sent for the first time, its pointers
are adjusted to indicate it was sent - b->pos moved to b->last, and
buffer's size become zero. Second attempt to send the same buffer
will expectedly trigger the "zero size buf" check.

> WHAT IS THE CORRECT WAY TO ACCOMPLISH MY NEED? (I searched a lot but I only
> found [3] which has rc=-2 rather than -1)
> [3] http://web.archiveorange.com/archive/v/yKUXMLzGBexXA3PccJa6

Trivial aproach is to prepare full output chain, and then send it
using single ngx_http_output_filter() call.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

custom handler module - dynamic response with unknown content length

Yasser Zamani February 28, 2014 02:16PM

Re: custom handler module - dynamic response with unknown content length

Maxim Dounin February 28, 2014 07:12PM

Re: custom handler module - dynamic response with unknown content length

Yasser Zamani March 01, 2014 04:20AM

Re: custom handler module - dynamic response with unknown content length

Maxim Dounin March 01, 2014 06:32AM

Re: custom handler module - dynamic response with unknown content length

Yasser Zamani March 01, 2014 09:58AM

Re: custom handler module - dynamic response with unknown content length

Yasser Zamani March 01, 2014 12:28PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 206
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready